Megalextoria
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.

Home » Digital Archaeology » Computer Arcana » Apple » Apple II » Creating color text characters on the II in HGR?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Creating color text characters on the II in HGR? [message #387782] Mon, 14 October 2019 20:46 Go to next message
Anonymous
Karma:
Originally posted by: Matthew Power

I played around in HGR over the weekend, seeing if I could recreate the II font (40 cols) with colors.

I started with this example from the great book Applesoft Basic Subroutines and Secrets:

5 REM *** BIT MAPPED S ***
10 HGR : POKE - 16301,0: HOME
20 VTAB 22: INPUT "ENTER STARTING ADDRESS OF BLOCK ";AD
30 IF AD = 0 THEN 99
40 FOR A = AD TO AD + (7 * 1024) STEP 1024
50 READ B: POKE A,B
60 NEXT A
70 RESTORE : GOTO 20
99 HOME : END
1000 DATA 0,28,34,2,28,32,34,28

And as the book says, that creates the letter "S" (address 8192 places it at top left). It lights up the correct pixels, in white. The book mentions the "unused high bit", *0* would be for color, but either I keep putting in the wrong values or this isn't the correct method for color characters. Any values I put in that bit just add dots over the S, still in white.

So I tried a different approach with HPLOT referencing the charts in the book. That DOES work, and doing gave me a good lesson on which pixels will light up depending on the hcolor chosen. But it seems like a looong solution that would probably ultimately run slowly in applesoft.

The I remembered something called shape tables. But information on how to use them seems a bit scant.

So my questions are: Has anyone worked with creating colored text in HGR? Are shape tables the way to go? Is there a recommended book for learning how to create shape tables?

Thanks for reading.
Creating color text characters on the II in HGR? [message #387784 is a reply to message #387782] Mon, 14 October 2019 23:23 Go to previous messageGo to next message
gids.rs is currently offline  gids.rs
Messages: 1395
Registered: October 2012
Karma: 0
Senior Member
The program is fine. Just change the data values to these

1000 DATA 21,1,1,21,16,16,21,0 : rem violet
or
1000 DATA 42,2,2,42,32,32,42,0 : rem green

You will lose detail in colored characters, so the characters will look blocky. Just remember in hi-res, to get colored pixels, make sure that 2 consecutive pixels are not turned on, otherwise you get white characters.

To get other colors, add 128 to each of the values in the data statements
Re: Creating color text characters on the II in HGR? [message #387785 is a reply to message #387782] Mon, 14 October 2019 23:32 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: awanderin

Matthew Power <matthewmpower@gmail.com> writes:

> I played around in HGR over the weekend, seeing if I could recreate
> the II font (40 cols) with colors.
>
> I started with this example from the great book Applesoft Basic
> Subroutines and Secrets:
>
> 5 REM *** BIT MAPPED S ***
> 10 HGR : POKE - 16301,0: HOME
> 20 VTAB 22: INPUT "ENTER STARTING ADDRESS OF BLOCK ";AD
> 30 IF AD = 0 THEN 99
> 40 FOR A = AD TO AD + (7 * 1024) STEP 1024
> 50 READ B: POKE A,B
> 60 NEXT A
> 70 RESTORE : GOTO 20
> 99 HOME : END
> 1000 DATA 0,28,34,2,28,32,34,28
>
> And as the book says, that creates the letter "S" (address 8192 places
> it at top left). It lights up the correct pixels, in white. The book
> mentions the "unused high bit", *0* would be for color, but either I
> keep putting in the wrong values or this isn't the correct method for
> color characters. Any values I put in that bit just add dots over the
> S, still in white.
>
> So I tried a different approach with HPLOT referencing the charts in
> the book. That DOES work, and doing gave me a good lesson on which
> pixels will light up depending on the hcolor chosen. But it seems like
> a looong solution that would probably ultimately run slowly in
> applesoft.
>
> The I remembered something called shape tables. But information on how
> to use them seems a bit scant.
>
> So my questions are: Has anyone worked with creating colored text in
> HGR? Are shape tables the way to go? Is there a recommended book for
> learning how to create shape tables?

If you want text that is all the same color, you will likely have to
make the characters wider. As you've seen with using HPLOT, you can
only draw certain colors in certain positions.

For example, if you wanted a green "S", you could plot this:

......G. G.G....
....G... ....G..
....G... .......
......G. G.G....
........ ....G..
....G... ....G..
......G. G.G....

You could draw in basic with:

10 HGR
20 FOR A = 8192 to 15360 STEP 1024
30 READ D1, D2
40 POKE A, D1: POKE A+1, D2
50 NEXT
60 DATA 32,5, 8,16, 8,0, 32,5, 0,16, 8,16, 32,5, 0,0


where "." is an unlit pixel and "G" is a lit pixel in an even column
giving green (with the high bit off). If you had the high bit on, you
would instead get orange or red, depending on your monitor and/or
eyes. :)

This example of course is 14 pixels wide, or two screen bytes wide.

You could try for a green, normal-width "S" like so:

even screen odd screen
byte position byte position
....G... ..G....
..G...G. G...G..
..G..... G......
....G... ..G....
......G. ....G..
..G...G. G...G..
....G... ..G....

Not quite as visually pleasing, as you're trading horizontal resolution
for color similarity, and how even/odd column characters have to be
encoded differently. If you stored the "odd" green-"S" values into an
even column, they would be violet, and likewise for the "even" green-"S"
values into an odd column.

These could be drawn with:

(adding to the above program)

100 FOR A = 8232 TO 15400 STEP 1024
110 READ D1, D2
120 POKE A, D1: POKE A + 3, D2: REM DRAW GREEN "S"
130 POKE A + 41, D1: POKE A + 44, D2: REM DRAW VIOLET "S"
140 NEXT
150 DATA 8,4, 34,17, 2,1, 8,4, 32,16, 34,17, 8,4, 0,0


--
--
Jerry awanderin at gmail dot com
Re: Creating color text characters on the II in HGR? [message #387786 is a reply to message #387785] Mon, 14 October 2019 23:43 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: awanderin

I made a slight change. See the modified line 60 below.


I <awanderin@gmail.com> wrote:

> Matthew Power <matthewmpower@gmail.com> writes:
>
>> I played around in HGR over the weekend, seeing if I could recreate
>> the II font (40 cols) with colors.
>>
>> I started with this example from the great book Applesoft Basic
>> Subroutines and Secrets:
>>
>> 5 REM *** BIT MAPPED S ***
>> 10 HGR : POKE - 16301,0: HOME
>> 20 VTAB 22: INPUT "ENTER STARTING ADDRESS OF BLOCK ";AD
>> 30 IF AD = 0 THEN 99
>> 40 FOR A = AD TO AD + (7 * 1024) STEP 1024
>> 50 READ B: POKE A,B
>> 60 NEXT A
>> 70 RESTORE : GOTO 20
>> 99 HOME : END
>> 1000 DATA 0,28,34,2,28,32,34,28
>>
>> And as the book says, that creates the letter "S" (address 8192 places
>> it at top left). It lights up the correct pixels, in white. The book
>> mentions the "unused high bit", *0* would be for color, but either I
>> keep putting in the wrong values or this isn't the correct method for
>> color characters. Any values I put in that bit just add dots over the
>> S, still in white.
>>
>> So I tried a different approach with HPLOT referencing the charts in
>> the book. That DOES work, and doing gave me a good lesson on which
>> pixels will light up depending on the hcolor chosen. But it seems like
>> a looong solution that would probably ultimately run slowly in
>> applesoft.
>>
>> The I remembered something called shape tables. But information on how
>> to use them seems a bit scant.
>>
>> So my questions are: Has anyone worked with creating colored text in
>> HGR? Are shape tables the way to go? Is there a recommended book for
>> learning how to create shape tables?
>
> If you want text that is all the same color, you will likely have to
> make the characters wider. As you've seen with using HPLOT, you can
> only draw certain colors in certain positions.
>
> For example, if you wanted a green "S", you could plot this:
>
> .....G. G.G....
> ...G... ....G..
> ...G... .......
> .....G. G.G....
> ....... ....G..
> ...G... ....G..
> .....G. G.G....
>
> You could draw in basic with:
>
> 10 HGR
> 20 FOR A = 8192 to 15360 STEP 1024
> 30 READ D1, D2
> 40 POKE A, D1: POKE A+1, D2
> 50 NEXT
> 60 DATA 32,5, 8,16, 8,0, 32,5, 0,16, 8,16, 32,5, 0,0

You might like this better (or you might not):

60 DATA 32,5, 40,20, 40,0, 32,5, 0,20, 40,20, 32,5, 0,0


>
>
> where "." is an unlit pixel and "G" is a lit pixel in an even column
> giving green (with the high bit off). If you had the high bit on, you
> would instead get orange or red, depending on your monitor and/or
> eyes. :)
>
> This example of course is 14 pixels wide, or two screen bytes wide.
>
> You could try for a green, normal-width "S" like so:
>
> even screen odd screen
> byte position byte position
> ...G... ..G....
> .G...G. G...G..
> .G..... G......
> ...G... ..G....
> .....G. ....G..
> .G...G. G...G..
> ...G... ..G....
>
> Not quite as visually pleasing, as you're trading horizontal resolution
> for color similarity, and how even/odd column characters have to be
> encoded differently. If you stored the "odd" green-"S" values into an
> even column, they would be violet, and likewise for the "even" green-"S"
> values into an odd column.
>
> These could be drawn with:
>
> (adding to the above program)
>
> 100 FOR A = 8232 TO 15400 STEP 1024
> 110 READ D1, D2
> 120 POKE A, D1: POKE A + 3, D2: REM DRAW GREEN "S"
> 130 POKE A + 41, D1: POKE A + 44, D2: REM DRAW VIOLET "S"
> 140 NEXT
> 150 DATA 8,4, 34,17, 2,1, 8,4, 32,16, 34,17, 8,4, 0,0
>
>
> --
> --
> Jerry awanderin at gmail dot com

--
--
Jerry awanderin at gmail dot com
Re: Creating color text characters on the II in HGR? [message #387787 is a reply to message #387782] Tue, 15 October 2019 01:13 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: fadden

On Monday, October 14, 2019 at 5:46:49 PM UTC-7, Matthew Power wrote:
> So my questions are: Has anyone worked with creating colored text in HGR? Are shape tables the way to go? Is there a recommended book for learning how to create shape tables?

Shape tables aren't especially quick. If you want to work with them, one of the Beagle Bros utilities comes with a very nice shape table editor. The Applesoft reference manual explains how to use them.

For an alternative approach, see https://youtu.be/z2RFGVoaROE?t=10

It's using line-drawn fonts, although to keep things simple the data file has entire phrases rather than each individual character. (See the LINEFONT notes in https://github.com/fadden/fdraw/blob/master/docs/demos.md .) This has the advantage that it can be scaled to an arbitrary size, but drawing lines will be much slower than drawing bitmaps.

Synergistic Software's "Higher Text" utility has a mode where it draws double-wide fonts, which can be drawn in color. There's a nice screen shot at https://archive.org/details/a2woz_Higher_Text_II_1980_Synerg istic_Software .. I think this is what you want (either as the solution, or as the approach for your own solution).
Creating color text characters on the II in HGR? [message #387790 is a reply to message #387782] Tue, 15 October 2019 10:30 Go to previous messageGo to next message
Michael AppleWin Debu is currently offline  Michael AppleWin Debu
Messages: 1262
Registered: March 2013
Karma: 0
Senior Member
Matthew,

Welcome to the esoteric Apple ][ graphics scene!

I would highly recommend reading my tutorial:

https://github.com/Michaelangel007/apple2_hgr_font_tutorial

Shape tables are tempting to use (scaling + rotation) but they are crap for speed. With only a 1 Mhz CPU using memory mapped graphics we (usually) need all the performance possible for font rendering. But I don't know the run-time requirements of your software so shape tables may be "good enough" for you.

If you want speed then you'll probably want a small machine language font blitter tucked away at $300-$3BF and the HGR font data at $6000 - $63FF (for 128 glyphs of 7x8 px).

Your font blitter may need to know if you are writing into an even or odd scanline byte (column).

For example if you do

HGR

and then POKE 8192,1 (byte 0) you'll notice this pixel is magenta.

Now if you poke 8193,1 (byte 1) you'll notice this pixel is green.

And if you poke 8194,1 (byte 3) you'll notice the pixel is now back to magenta.

There are FOUR permutations:

- pixel in even column/odd byte column
- high bit is cleared/set (to select the byte palette: clear = green/magenta or set = blue/orange.)

The reason I use 1 is that this could be part of the 7x8 scanline data for a "!" glyph:

1
1
1
1
1
0
1
0


There are basically two ways to get consistent color from byte to byte.

* Shift the scan line data at run-time. UGH
* Use two fonts (one designed for even byte columns and the other designed for odd byte columns). Double UGH.

You'll have to decide between the classic Speed vs Space trade off.

If we wanted to have our "!" glyph in byte column 1 be the same color as byte column 0 then notice that we need to shift the bits LEFT to make them appear in the next RIGHT pixel (due to HGR bits being displayed reversed.)

2
2
2
2
2
0
2
0

The problem now is that you will have inconsistent kerning (spaces between rendered glyphs) but there is nothing we can do about that for color text. (One of the reasons people just use two consecutive bits for white glyphs.)

The other problem is that if we want a blue/orange font color we will need to set the high bit. Bit 7 = 128 (decimal) = $80 (hexadecimal)

I do have a font editor that makes it trivial to create 7x8 glyphs but let me see if I can get it released since it is one of the tools for an Apple //e game I'm working on.

Feel free to ask questions.

Welcome again to the fun world of Apple 2 graphics!
Re: Creating color text characters on the II in HGR? [message #387791 is a reply to message #387790] Tue, 15 October 2019 11:35 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: fadden

On Tuesday, October 15, 2019 at 7:30:04 AM UTC-7, Michael 'AppleWin Debugger Dev' wrote:
> There are basically two ways to get consistent color from byte to byte.
>
> * Shift the scan line data at run-time. UGH
> * Use two fonts (one designed for even byte columns and the other designed for odd byte columns). Double UGH.

I think you'd be better off with a "thick" white font that has the high bits set, and then just AND off every other pixel and possibly the high bit as you're drawing. You can EOR #$7f the mask as you walk across the screen, or set up a parallel array of 40 mask bytes when the color changes and use the HGR line index.

A single-byte-wide font in color would give you 3x8 for glyphs in some columns, 4x8 in others, which is probably going to look nasty. A double-wide font will look much better. If you restrict glyphs to starting in even columns it will look more consistent.

> I do have a font editor that makes it trivial to create 7x8 glyphs but let me see if I can get it released since it is one of the tools for an Apple //e game I'm working on.

I have a very vague recollection of a font editor from Softape. I think "Screen Machine" is it. https://www.brutaldeluxe.fr/projects/cassettes/softape/softa pe_catalog_1980.pdf
Re: Creating color text characters on the II in HGR? [message #387793 is a reply to message #387791] Tue, 15 October 2019 12:01 Go to previous messageGo to next message
Michael AppleWin Debu is currently offline  Michael AppleWin Debu
Messages: 1262
Registered: March 2013
Karma: 0
Senior Member
On Tuesday, October 15, 2019 at 8:35:34 AM UTC-7, fadden wrote:
> I think you'd be better off with a "thick" white font that has the high bits set, and then just AND off every other pixel and possibly the high bit as you're drawing. You can EOR #$7f the mask as you walk across the screen, or set up a parallel array of 40 mask bytes when the color changes and use the HGR line index.

The thick white font and mask off even/odd pixel columns is a great optimization / idea! Very nice.


I could see the inner loop being something along the lines of:


LDX color
LDA ColorEvenMask,x
STA EvenMask+1

LDA ColorOddMask,x
STA OddMask+1

FetchEvenColumn
LDA (zFontPtr),Y
EvenMask
EOR #$7F ; **SELF-MODIFIED for green/magenta or blue/orange

FetchOddColumn
LDA (zFontPtr),Y
EOR #$7F ; ***SELF-MODIFIED for green/magenta or blue/orange
ASL

ColorEvenMask
DB $7F ; Black #1
DB $2A ; Green
DB $55 ; Magenta
DB $00 ; White #1
DB $FF ; Black #2
DB $D5 ; Blue
DB $AA ; Orange
DB $00 ; White #2

ColorOddMask
DB $7F ; Black #1
DB $55 ; Green
DB $2A ; Magenta
DB $00 ; White #1
DB $FF ; Black #2
DB $AA ; Blue
DB $D5 ; Orange
DB $00 ; White #2

I probably buggered up the white and black masks but the color ones should be good.


> or set up a parallel array of 40 mask bytes when the color changes and use the HGR line index.

That probably wouldn't be needed for single glyph/character rendering but for string drawing I definitely could see that being used.



> 3x8 for glyphs in some columns, 4x8 in others, which is probably going to look nasty. A double-wide font will look much better.


Yup that's the standard trade-off when working with color on the HGR screen.. You can have resolution (560x192) or color (140x192). Pick one. :-)

A double wide font is pretty much a required if you want a custom color per glyph. Lode Runner does this. The maximum number of characters per scanline is 28 characters where each glyph is (280 px/tile / 28 tiles) = 14 pixels.

Using a double wide font also means you don't have kerning issues.

Michael
Re: Creating color text characters on the II in HGR? [message #387804 is a reply to message #387785] Tue, 15 October 2019 22:55 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: Matthew Power

> .....G. G.G....
> ...G... ....G..
> ...G... .......
> .....G. G.G....
> ....... ....G..
> ...G... ....G..
> .....G. G.G....
>
> You could draw in basic with:
>
> 10 HGR
> 20 FOR A = 8192 to 15360 STEP 1024
> 30 READ D1, D2
> 40 POKE A, D1: POKE A+1, D2
> 50 NEXT
> 60 DATA 32,5, 8,16, 8,0, 32,5, 0,16, 8,16, 32,5, 0,0

I think I understand, you made two blocks of 7 to create a larger character? D1 and D2 reference each block of 7 if I have it right. I put your example into a text editor to see the grid. Even pixels are green. Can be toggled, but I don't understand doing that just yet because...

I thought much about how you were getting the decimal values from binary for the data statements. It didn't make any sense to me until I looked at it backwards. Is that right? Binary backwards with a bit on the end? Is that last bit the high bit that can be toggled?
Re: Creating color text characters on the II in HGR? [message #387805 is a reply to message #387804] Tue, 15 October 2019 23:21 Go to previous messageGo to next message
Michael AppleWin Debu is currently offline  Michael AppleWin Debu
Messages: 1262
Registered: March 2013
Karma: 0
Senior Member
> It didn't make any sense to me until I looked at it backwards.

Yes, the HGR screen displays bits in reverse. Here is a handy table:

Dec Binary Hex Pixels
1 0000_0001 $01 M------
2 0000_0010 $02 -G-----
4 0000_0100 $04 --M----
8 0000_1000 $08 ---G---
16 0001_0000 $10 ----M--
32 0010_0000 $20 -----G-
64 0100_0000 $40 ------M

Dec Binary Hex Pixels
129 1000_0001 $81 B------
130 1000_0010 $82 -O-----
132 1000_0100 $84 --B----
136 1000_1000 $88 ---O---
144 1001_0000 $90 ----B--
160 1010_0000 $A0 -----O-
192 1100_0000 $C0 ------B

Each byte can display 7 pixels.

Legend:
M = Magenta
G = Green
B = Blue
O = Orange

Technically Blue and Orange are shifted over half a pixel but you can ignore this for now.

I would recommend playing around with my HGR Byte Editor:
https://github.com/Michaelangel007/apple2_hgrbyte

Michael
Re: Creating color text characters on the II in HGR? [message #387806 is a reply to message #387804] Tue, 15 October 2019 23:24 Go to previous messageGo to next message
Michael AppleWin Debu is currently offline  Michael AppleWin Debu
Messages: 1262
Registered: March 2013
Karma: 0
Senior Member
> is that last bit the high bit that can be toggled?

The high bit determines the palette for a grouping of 7 pixels. In AppleSoft BASIC the values poked can be categorized as:

Dec Color
---------------------------------------------------------
000 Some combination of black, white, green, and magenta
:
127 Some combination of black, white, green, and magenta

128 Some combination of black, white, blue and orange
:
255 Some combination of black, white, blue and orange

Michael
Re: Creating color text characters on the II in HGR? [message #387812 is a reply to message #387804] Wed, 16 October 2019 02:55 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: awanderin

Matthew Power <matthewmpower@gmail.com> writes:

>> .....G. G.G....
>> ...G... ....G..
>> ...G... .......
>> .....G. G.G....
>> ....... ....G..
>> ...G... ....G..
>> .....G. G.G....
>>
>> You could draw in basic with:
>>
>> 10 HGR
>> 20 FOR A = 8192 to 15360 STEP 1024
>> 30 READ D1, D2
>> 40 POKE A, D1: POKE A+1, D2
>> 50 NEXT
>> 60 DATA 32,5, 8,16, 8,0, 32,5, 0,16, 8,16, 32,5, 0,0
>
> I think I understand, you made two blocks of 7 to create a larger
> character? D1 and D2 reference each block of 7 if I have it right. I
> put your example into a text editor to see the grid. Even pixels are
> green. Can be toggled, but I don't understand doing that just yet
> because...

Yes, 7 displayed bits per byte.

> I thought much about how you were getting the decimal values from
> binary for the data statements. It didn't make any sense to me until I
> looked at it backwards. Is that right? Binary backwards with a bit on
> the end? Is that last bit the high bit that can be toggled?

Right, the bits are pumped out lowest first to the video circuitry. The
high bit is not displayed, but if set, causes a half-pixel shift (70 ns
delay), which effectively generates a different set of colors.

--
--
Jerry awanderin at gmail dot com
Re: Creating color text characters on the II in HGR? [message #387840 is a reply to message #387805] Wed, 16 October 2019 20:11 Go to previous message
Anonymous
Karma:
Originally posted by: Matthew Power

  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Can we end the Syndicomm problem? Mike Westefield you out there>
Next Topic: VidHD - Saving Parameters?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Tue Apr 16 04:41:59 EDT 2024

Total time taken to generate the page: 0.19987 seconds