Hires Graphics

Basic and Machine Language

Moderator: Moderators

User avatar
Mike
Herr VC
Posts: 4842
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

3D Pie Chart

Post by Mike »

Adding another 3D program for MINIGRAFIK, this is a pie chart:

Code: Select all

10 REM ** 3D PIE CHART
11 READN:DIMA(N-1):S=0:FORT=1TON:READA:S=S+A:A(T-1)=S:NEXT
12 POKE36879,127:POKE646,2:@ON:@CLR:K1=79:K2=112
13 FORU=0TO56:V=INT(SQR(6241-U*U)+.5)
14 @1,K1+U,K1+V:@1,K1+U,K1-V:@1,K1-U,K1-V:@1,K1-U,K1+V
15 @1,K1+V,K1+U:@1,K1+V,K1-U:@1,K1-V,K1-U:@1,K1-V,K1+U
16 @1,K1+U,K2+V:@1,K1-U,K2+V:@1,K1+V,K2+U:@1,K1-V,K2+U
17 NEXT:@1,0,K1TO0,K2:@1,2*K1,K1TO2*K1,K2:@1,K1,K1TOK1,0
18 FORT=1TON-1:A=2*{PI}*A(T-1)/S:U=INT(K1*SIN(A)+.5):V=INT(K1*COS(A)+.5)
19 @1,K1,K1TOK1+U,K1-V:IFV<0THEN:@1,K1+U,K1-VTOK1+U,K2-V
20 NEXT
21 GETA$:IFA$=""THEN21
22 @RETURN:END
23 :
24 REM ** CHART DATA
25 DATA 8
26 DATA 3,8,4,5,5,7,1,9
Line 25 contains the number of pieces.
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Post by nippur72 »

Some questions about the MINIGRAFIK:

1) is its source code available?

2) why the odd screen size 20x24 which uses only 480 characters instead of the standard size 22x23 that uses 508 characters?

3) in your opinion, is this graphic mode suitable for developing games, like C16 and Plus4 games where there are no hardware sprites?
User avatar
Mike
Herr VC
Posts: 4842
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

1) is its source code available?

Yes. You are the first one who asks for this. Currently the source code uses the inline assembler of HI BASIC, and would need some work to port to DASM.

2) why the odd screen size 20x24 which uses only 480 characters instead of the standard size 22x23 that uses 508 characters?

When doing bitmapped graphics, one usually uses double-height characters to minimize the space for the text map. So MINIGRAFIK actually only uses 240 chars to display the graphics. MINIGRAFIK is designed to be interoperable with BASIC. The lower 1K therefore cannot be used to store the text map. MINIGRAFIK stores char map and bitmap entirely in the space $1000-$1FFF.

The maximum resolution possible under these circumstances derives as follows: you need 17 bytes (1 byte in the text map, 16 bytes char definition) to display a 8x16 block. 4096/17 ~= 240,9. 240 chars nicely fit into a 20x12 grid, which gives the 160x192 (=20*8 * 12*16) resolution. Since the pixels have a rectangular shape, you'll still also get an rectangular shape of the whole display.

3) in your opinion, is this graphic mode suitable for developing games, like C16 and Plus4 games where there are no hardware sprites?

Yes. VicTragic's Parachute uses this mode. Since the bitmap is built in column-major order, the addressing is indeed even simpler, than with the hires-mode on the other CBMs.

Greetings,

Michael
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Post by nippur72 »

Michael thank you for the replies. I've learned something I didn't knew about double height mode, namely that is spans over 4K bitmap, where normal characters use only 2k.

Now I see why everything was made the way it is.

I instead assumed that the bitmap mode was made with a raster trick, by flipping 36868 between 253 and 254 at start and middle of the page, so that characters would be read from 5120 and 6144, overcoming the 2K bitmap limit.

And, yes, I am interested in the source, I need only the screen and pointers setup part.
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

The VIC-I chip itself can actually address up to 16K, of which 10K is present in a real VIC-20 (4K ROM, 1K colour nybbles, 5K RAM) and the rest is unconnected address space as explored in most recent demos.

Of course a fully bitmapped screen without using raster tricks could not be bigger than 256*16 = 4K, plus some memory for screen matrix and colour matrix, but with e.g. more RAM the bitmap could be double buffered.
Anders Carlsson

Image Image Image Image Image
User avatar
Mike
Herr VC
Posts: 4842
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

nippur72 wrote:And, yes, I am interested in the source, I need only the screen and pointers setup part.
This is the code executed by the @ON command:

Code: Select all

.On
 CLC            ; set up char map
 LDA #$10       ; first char is 'P', accessing $1100
 TAY
.On_00
 STA $0FF0,Y
 ADC #$0C
 BCC On_01
 SBC #$EF
.On_01
 INY
 BNE On_00
 LDY #$05       ; program VIC registers
.On_02
 CLC
 LDA $EDE4,Y
 ADC Offset,Y
 STA $9000,Y
 DEY
 BPL On_02
 RTS

.Offset
 EQUB $02
 EQUB $FE
 EQUB $FE
 EQUB $EB
 EQUB $00
 EQUB $0C
The bitmap starts at $1100, the address of a pixel is calculated thus (done with a table lookup):

Code: Select all

AD=4352+192*INT(X/8)+Y
The definitions of {SHIFT-M} and reverse {SHIFT-M} at $8268 and $8668 provide convenient bitmasks for setting or clearing single points.
Last edited by Mike on Wed Aug 26, 2009 10:05 am, edited 1 time in total.
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Today a guy mailed me asking how to draw bitmapped graphics on an unexpanded VIC-20 without using Super Expander. I posted a link to MINIGRAFIK, converted Mike's docs to MS Word and added a few examples.

The other guy now wrote me that he's not interested in this extention, but rather would like to draw his own hires graphics from Basic. *sigh*
Anders Carlsson

Image Image Image Image Image
User avatar
Mike
Herr VC
Posts: 4842
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

I had dug out the original MINIGRAFIK extension (download) some time ago. It runs on an unexpanded VIC, or with +3K, but only provides 128x128 pixels. And, of course, my later extensions, like line drawing, (easy) multi-colour support, and load/save aren't there at all.
carlsson wrote:[...]and added a few examples.
If these are your own, would you like to post them here?

Greetings,

Michael

Edit: Listing of BASIC DATA loader replaced by d/l link, courtesy tokra.
Last edited by Mike on Tue Aug 02, 2016 9:30 am, edited 2 times in total.
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

No, I copy and pasted yours + one from NBLA000.

In the end I wrote a Basic program that defines a 128x96 bitmap with space for regular text below, but pointed out how slow it was.
Anders Carlsson

Image Image Image Image Image
User avatar
Mike
Herr VC
Posts: 4842
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

carlsson wrote:Today a guy mailed me asking how to draw bitmapped graphics on an unexpanded VIC-20 without using Super Expander. [...] The other guy now wrote me that he's not interested in [MINIGRAFIK], but rather would like to draw his own hires graphics from Basic. *sigh* [...] In the end I wrote a Basic program that defines a 128x96 bitmap with space for regular text below, but pointed out how slow it was.
Well there are sometimes strange people around. What did that guy expect, anyway? With only unexpanded memory, and BASIC only you can't jump very far. Really, pearls thrown before the swine.

Michael
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

He's actually working with up to 8-16K expansion memory, which means a bit of moving start of Basic to have room for any custom graphics at all.

Anyway, this was the program I wrote for an unexpanded VIC:

Code: Select all

10 POKE56,22:POKE52,22:POKE648,22:CLR
20 V=36864:POKEV+5,208:POKEV+15,10:PRINT"{CLR}{13 DOWN}{YEL}A SINE CURVE"
30 FORY=0TO11:FORX=0TO15:POKE5632+Y*22+X,64+X*12+Y:NEXTX,Y
40 POKEV+5,222:FORI=0TO511:POKE6144+I,PEEK(32768+I):NEXT
50 FORI=0TO1535:POKE6656+I,0:NEXT
60 FORX=0TO127:Y=INT(48+SIN(X/64*pi)*44)
70 A=6656+INT(X/8)*96+Y:POKEA,PEEK(A)OR2^(7-XAND7)
80 NEXT
:roll:
Anders Carlsson

Image Image Image Image Image
6502dude
megacart
Posts: 1581
Joined: Wed Dec 01, 2004 9:53 am

Post by 6502dude »

carlsson wrote:Anyway, this was the program I wrote for an unexpanded VIC:
Cool!
Image Mega-Cart: the ultimate cartridge for your Commodore Vic-20
User avatar
Mike
Herr VC
Posts: 4842
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

carlsson wrote:[...] working with up to 8-16K expansion memory [...] means a bit of moving start of Basic to have room for any custom graphics at all.
...which, of course, is automatically done by MINIGRAFIK.

Except the PRINT statement - which isn't supported by MINIGRAFIK at the moment -, your program is reduced to this:

Code: Select all

20 POKE36879,10:POKE646,1
30 @ON
50 @CLR
60 FORX=0TO127:Y=INT(48+SIN(X/64*{PI})*44)
70 @1,X,Y
80 NEXT
:wink:

I kept the line numbers for equivalent statements.

My program runs 5,3 sec, yours 32,8 sec - most of which is spent for setting up the hires screen, clearing it, and copying the charset. As you said.
User avatar
Mike
Herr VC
Posts: 4842
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Earth globe

Post by Mike »

Hi,

This program displays an Earth globe. You specify the longitude, and latitude, that is centered. The north pole is always facing up.

In line 11, R1 can be adapted for different aspect ratios: R1=57 is correct for PAL; NTSC, and VICE should use R1=71, and R1=47, respectively. Line 11 also contains a {PI} symbol. That noted, any tokenizer should work.

Cheers,

Michael

Edit: type-in listing removed. It is contained in the MG batch suite.
Last edited by Mike on Sat Jul 28, 2012 10:22 am, edited 1 time in total.
User avatar
orion70
VICtalian
Posts: 4341
Joined: Thu Feb 02, 2006 4:45 am
Location: Piacenza, Italy
Occupation: Biologist

Post by orion70 »

Another wonder to show to my C64 friends :D .
Here's a screenshot of the new desktop, after a bit of GIMPing on the image:
Image
I'm working on the animated gif of the revolving globe now - it will take a while, but the result will be the first 3D animation made with a Commodore VIC-20 (well, with a little help from other tools, but... :P ).
Post Reply