Hires Graphics

Basic and Machine Language

Moderator: Moderators

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

3D Bar Chart

Post by Mike »

Here's another application for MINIGRAFIK. A 3D Bar Chart. No more need to use E**el for this. ;)

I was lucky to see the design allows for 12 bars over the screen width. So the program can accommodate the display of the fuel consumption of your car over the year, or similar things.

Greetings,

Michael

Code: Select all

1 REM ** 3D BAR CHART
2 @ON:@CLR
3 Y=191:Z=175:S=25:GOSUB10
4 Y=188:FORX=6TO138STEP12:READZ:GOSUB20:NEXT
5 GETA$:IFA$=""THEN5
6 @RETURN:END
7 :
10 @1,0,YTO147,Y:@1,147,YTO159,Y-12
11 FORT=0TOZSTEPS
12 @1,0,Y-TTO12,Y-T-12:@1,12,Y-T-12TO159,Y-T-12
13 NEXT
14 @1,0,YTO0,Y-Z:@1,12,Y-12TO12,Y-Z-12:@1,159,Y-12TO159,Y-Z-12
15 RETURN
16 :
20 IFZ<2THEN23
21 FORT=1TO8:@0,X+T,Y-1TOX+T,Y-Z+1:NEXT
22 FORT=1TO5:@0,X+T+9,Y-T-1TOX+T+9,Y-T-Z+1:NEXT
23 FORT=1TO5:@0,X+T+1,Y-T-ZTOX+T+8,Y-T-Z:NEXT
24 @1,X,YTOX+9,Y:@1,X+9,YTOX+15,Y-6
25 @1,X,YTOX,Y-Z:@1,X+9,YTOX+9,Y-Z:@1,X+15,Y-6TOX+15,Y-Z-6
26 @1,X,Y-ZTOX+9,Y-Z:@1,X+9,Y-ZTOX+15,Y-Z-6
27 @1,X,Y-ZTOX+6,Y-Z-6:@1,X+6,Y-Z-6TOX+15,Y-Z-6
28 RETURN
29 :
30 DATA 0,1,2,3,10,20,55,175,111,33,81,47
Thomas Hechelhammer
Vic 20 Dabbler
Posts: 79
Joined: Thu Jun 09, 2005 11:51 pm
Location: Germany

Post by Thomas Hechelhammer »

Thanks for the examples.

I was wondering how the bitmap is arranged so I looked here and there:

Bitmap and chars start both at 1000.

Chars are arranged in a 20x12 char map as follows:

Code: Select all

10 1c 28 34 40 4c 58 64 70 7c 88 94 a0 ac b8 c4 d0 dc e8 f4
11 1d 29 35 41 4d 59 65 71 7d 89 95 a1 ad b9 c5 d1 dd e9 f5
.. ..	     					              				.. ..
1a 26 32 3e 4a 56 62 6e 7a 86 92 9e aa b6 c2 ce da e6 f2 fe
1b 27 33 3f 4b 57 63 6f 7b 87 93 9f ab b7 c3 cf db e7 f3 ff
This area is between 1000 and 10ef (240 characters). Bit 1 in $9003 is set, so we have double-chars which give us direct access to 240 x 2 x 8 x 8 = 30720 pixel (which is 160 (X-Axis) x192 (Y-Axis)).

The very first double-character $10 in the upper left corner (8x16 pixel) uses the bitmap from chars $20 and $21, which are memory-locations 1000 + $20 x 8 = 1100 to 110f (16 bytes).

For saving pictures simply store the memory from 1000 to 1fff, and write the following bytes to 9000 – 900f : 0e 24 14 19 00 cc 57 ea 00 00 00 00 00 00 00 1b

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

Post by Mike »

Thomas Hechelhammer wrote:I was wondering how the bitmap is arranged so I looked here and there:

Bitmap and chars start both at 1000.
Yep. With double-height characters, one needs 17 Bytes (1 text byte, 16 bitmap bytes) to display an 8x16 pixel cell. I didn't want to use the bottom 1K, so the calculation was:

4096/17 ~= 240.94

Of course we cannot use fractions of a cell. But 240 chars can be neatly arranged in a 20x12 map. :) So we have optimal use of the upper 4K built-in RAM.
Thomas Hechelhammer wrote:For saving pictures simply store the memory from 1000 to 1fff, and write the following bytes to 9000 – 900f : 0e 24 14 19 00 cc 57 ea 00 00 00 00 00 00 00 1b
Since the text map is always the same, you can restore it from MINIGRAFIK, and you don't need to save the text map:

Save picture from program:

Code: Select all

SYS57809(N$),8,1:POKE193,0:POKE194,17 
POKE780,193:POKE781,0:POKE782,32:SYS65496
Load picture:

Code: Select all

@CLR:SYS57809(N$),8,1:POKE780,0:SYS65493:@ON
@CLR clears the screen bitmap - which isn't needed here -, but also initialises the colour RAM. @ON then writes the text map, and sets the needed values in the VIC registers, which are correct for both PAL and NTSC.

Greetings,

Michael

Edit: MINIGRAFIK 4.02 features @SAVE and @LOAD commands to save and load images.
Last edited by Mike on Thu Oct 30, 2008 2:54 am, edited 1 time in total.
User avatar
GreyGhost
Vic 20 Nerd
Posts: 525
Joined: Wed Oct 05, 2005 11:10 pm

Post by GreyGhost »

Just playing around with this program. Here is a graphical picture of just how finite the RND(1) function really is. Some number combos never even come up. I ran this in VICE so I hope that's what's doing it. You'll have to use warp mode to see what I mean.

10 @ON:@CLR
20 @1,INT(RND(1)*160,INT(RND(1)*192)
30 GOTO 20


If you replace the 1 with a 0 it really gets crappy.

Later,
Rob
User avatar
GreyGhost
Vic 20 Nerd
Posts: 525
Joined: Wed Oct 05, 2005 11:10 pm

Post by GreyGhost »

Can any one come up with a way to fill the screen randomly like this? :?
Rob
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

GreyGhost wrote:I ran this in VICE so I hope that's what's doing it.
Hi, Rob!

This is not VICE's fault. The RND() function is broken. I wrote a posting about that some months ago.

The replacement, that I posted, indeed manages to fill the entire screen. However, its BASIC implementation is rather slow. Furthermore, your fill routine as such slows down exponentially (like a radio-active decay of the white pixels).

Better is an algorithm, that produces pixel-addresses exactly once - but still semi-random. You might try this:

Code: Select all

1 @ON:@CLR
2 X=0:Y=0
3 FORT=1TO30880
4 X=X+39:IFX>159THENX=X-160
5 Y=Y+74:IFY>192THENY=Y-193
6 IFY<192THEN:@1,X,Y
7 NEXT
8 GETA$:IFA$=""THEN8
9 @RETURN
Greetings,

Michael

Edit: Corrected error in line 5
Last edited by Mike on Thu Jan 11, 2007 1:47 am, edited 1 time in total.
User avatar
GreyGhost
Vic 20 Nerd
Posts: 525
Joined: Wed Oct 05, 2005 11:10 pm

Post by GreyGhost »

I assumed the x's in line 5 were supposed to be y's. That's neat. Though not what I'd call random. All kinds of patterns can be done changing the values added to x and y.
Rob
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

GreyGhost wrote:Though not what I'd call random.
How about this?

Code: Select all

1 S=1
2 @ON:@CLR
3 FORT=1TO65536
4 S=75*S:S=S-65537*INT(S/65537):R=S-1
5 IFR<30720THENY=INT(R/160):@1,R-160*Y,Y
6 NEXT
7 GETA$:IFA$=""THEN7
8 @RETURN
Greetings,

Michael
User avatar
GreyGhost
Vic 20 Nerd
Posts: 525
Joined: Wed Oct 05, 2005 11:10 pm

Post by GreyGhost »

Cool, you're quite the matha-magician. This one definitly appears random. Does this one also only produce the same number combos once? Can you explain a little on how it works?
Rob
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

This is number theory. The numbers from 0 to 65536 form a field, and 75 is relative prime to 65537 (the number of elements in the field).

That means:

Code: Select all

      k
S = 75  mod 65537
 k
is a sequence of numbers from 1 to 65536, which all appear exactly once (as you've guessed). The choice of the base 75 results in a seemingly random distribution. It is the same random generator that is used in the ZX81 and ZX Spectrum.

I then subtract 1 from the generated numbers to get a range from 0 to 65535, and then throw away all numbers from 30720 to 65535 as they don't correspond to pixels on the screen.

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

MINIGRAFIK 4.02

Post by Mike »

New version 4.02 of MINIGRAFIK!

- The draw commands and the point test function now also support multi-colour mode,
- @SAVE, @LOAD commands have been added for disk and tape access,
- faster start-up time (no more slow POKEing into memory from READ-DATA statements during start-up).

Edit: The executable of MINIGRAFIK is now part of the MG batch suite. The manual of MINIPAINT also contains instructions for using MG commands in your own programs.
Last edited by Mike on Thu Mar 15, 2012 10:02 am, edited 2 times in total.
Iltanen
Vic 20 Devotee
Posts: 200
Joined: Tue Jul 17, 2007 6:08 pm

Post by Iltanen »

That's a great program! But typing it in... I really should get a better way to transfer data to my VIC
gklinger
Vic 20 Elite
Posts: 2051
Joined: Tue Oct 03, 2006 1:39 am

Post by gklinger »

I haven't had a chance to test it yet but I copied and pasted the program into Power20 and saved the result out here. That should save you some typing. Being able to paste into the VIC's BASIC editor is such a lovely feature.

Update: Michael was kind enough to send me a working copy of the program along with the loader. Both are available on a d64 at the previously provided link.
Last edited by gklinger on Wed Apr 02, 2008 9:22 am, edited 1 time in total.
In the end it will be as if nothing ever happened.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

:oops:

I found a bug in version 4.01, in the newly introduced @SAVE command. A typical variant of code 'optimization' gone wrong, which in that case corrupts the colour RAM information of the saved image.

The bug has been fixed in 4.02.

Michael
gklinger
Vic 20 Elite
Posts: 2051
Joined: Tue Oct 03, 2006 1:39 am

Post by gklinger »

Thanks to Michael, version 4.02 is available from http://www.vex.net/~falco/petscii/minigrafik.zip.
In the end it will be as if nothing ever happened.
Post Reply