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

Post by Mike »

carlsson wrote:By the way, at what smaller resolution would this kind of animated globe be feasible? At 128x128 pixels each frame equals 2K if video and colour matrices are unchanged.

How long would it take to generate a frame in ML, and how many frames need to be precalculated if we want the globe to rotate at least one frame per second? Even then, the internal 4K RAM probably is best used for double buffering so we can copy graphics data into one half while displaying the other.
The following program displays the rotating Earth globe with 24 phases, in full resolution, at ~4 frames per second. It needs a fully expanded VIC-20, with RAM in BLK1, BLK2, BLK3, and BLK5.

Similarily to the first incarnation, 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 21 contains a {PI} symbol.

Main work is done by a ultra-fast line-routine, which does ~30000 pixels per second.

Cheers,

Michael

P.S.: It is now 00:53 CET, time to go to bed.

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.
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

I should've guessed you were on the task! :lol:

While I haven't tried it yet, I understand the MINI-GRAFIK program needs to be loaded. Then you seem to save (or is it load?) a file to disk. Is it a 24K memory dump of all the pre-calculated coordinates that your first program will generate?
Anders Carlsson

Image Image Image Image Image
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Post by Jeff-20 »

@1? @CLR?
High Scores, Links, and Jeff's Basic Games page.
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:... you seem to save (or is it load?) a file to disk.
Both. It is checked whether the file "LIN" already exists on disk, and whether it is the correct data for the aspect ratio R1 specified in line 11. If neither of these preconditions is true, then the program calculates new data for the file, which takes roughly 40 minutes. Doing that chore once is enough.
Is it a 24K memory dump of all the pre-calculated coordinates that your first program will generate?
Actually, the file "LIN" is 49 blocks in length.

Michael
User avatar
orion70
VICtalian
Posts: 4341
Joined: Thu Feb 02, 2006 4:45 am
Location: Piacenza, Italy
Occupation: Biologist

Post by orion70 »

Another programming wonder :shock: .
For the lazy ones, here's a disk with the rotating globe program (R1=47, works in fully expanded VICE emu). It's complete with the generated LIN file.

Instructions:

1) load"*",8,1
2) run
3) load"globe",8
4) run
5) Wait approx. two minutes (or press ALT+W)
6) Enjoy

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

Post by carlsson »

Finally a good use of the Warp mode in VICE. :-D

Jeff: unless it hasn't already been clear to you, almost all the Basic programs shown in this thread are based on that you already have Mike's MINI-GRAFIK extention loaded.
Anders Carlsson

Image Image Image Image Image
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Post by Jeff-20 »

oh yeah, i forgot. :oops:
High Scores, Links, and Jeff's Basic Games page.
User avatar
Mike
Herr VC
Posts: 4842
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

Hi, Jeff,

the examples in the thread should give a good idea, what is possible with MINIGRAFIK, and how to use it. The graphics in "VICtoria Deluxe", and "VICtoria Gold Ed.", from orion70, and me were also done with this extension.

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

Post by carlsson »

How about making a C interface to MINIGRAFIK so it can be included and called from e.g. cc65? So far I haven't written any VIC programs in C except for "porting" Contiki, but the other day I considered to give it a try. It should speed up development somewhat, while still giving a machine code program in the end. I don't know if hires graphics is the first I'd try out in C though, but ... it is an option.
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 »

The first pre-requisite is, that C source can be compiled to an executable with a BASIC start at $246B. Second, there must be no harmful clashes in zeropage usage.

With the exception of the @() function, all relevant routines in MINIGRAFIK are callable with JSR. Only parameter passing, and validation need be done in the C function wrappers.

The @() function itself must be re-implemented, although it can use internal routines for address calculation.

This would be the proposed API:

Code: Select all

typedef unsigned char byte;

void at_on(void);
void at_clr(void);
void at_return(void);
void at_plot(byte colour, byte x, byte y);
void at_line(byte colour, byte x1, byte y1, byte x2, byte y2);
byte at(byte x, byte y);
void at_save(const char *name, byte device);
void at_load(count char *name, byte device);
The POKEs to addresses 646, 36878, and 36879 can easily be replaced by macros.
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

MIKE - in response to continuing the thread in here now, hope you know what im referring to, i would have rather just kept it in that thread, but....

1) is that for unexpanded VICE ?
2) i dont know how to save as .d64 image on VICE
3) then what...
4) Well this thread started as me learning what a vic is and now im into assembly language basics, but I do want to know how to run this minigraphics program simply to learn the basic routines demonstrated and how i can implement them into assembly.
I dont know what a loader is i just know there is basic programs, machine language programs executed with a SYStem command, and self executing machine language programs .prg .bas .vsf are ones ive created and saved as a state in the emulator...

when i copy and paste that loader and type run , i run out of memory in line 12, im guessing i have to have it loaded as a prerequisite upon running minigraphiks, still dont know how to mike! Razz
User avatar
Mike
Herr VC
Posts: 4842
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

To refer to my post in the other thread:
Mike wrote:- First copy+paste the DATA loader of MINIGRAFIK 4.02 into VICE. This is the most recent version to date.
- SAVE this program as "LOADER" onto a *.d64 image.
- RUN the program. The file "MINIGRAFIK" is written on disk. This is the actual BASIC extension. Up to here, these steps need only be done once.

- LOAD the file "MINIGRAFIK", and RUN it. The VIC shows the start screen again, with slightly less memory available than before. MINIGRAFIK is now active.

There is no need to memorize a certain SYS address to start the extension, as it is already contained in the program. The correct SYS shows up, when you LIST it before starting. This SYS is executed for you, when you type RUN+Return.
Legacy wrote:1) is that for unexpanded VICE ?
No, it isn't. MINIGRAFIK needs at least an 8K RAM expansion. In VICE, look under Settings > VIC Settings ...
2) i dont know how to save as .d64 image on VICE
*.d64 image files contain the data of a whole 5 1/4" disc (one sided).

To create a *.d64 file in VICE:

- File > Attach disk image > Drive 8, you'll be presented with a file selection box.
- In the field 'New Image', enter a name, for example 'MINIGRAFIK', an ID, for example 'MG', select d64, but do not click yet 'create image'.
- Fill in the field 'File name', for example 'minigrafik.d64'.
- Click 'create image'.
- Click 'attach'.

The file 'minigrafik.d64' is now mounted as *.d64 disc image. You can now store files inside this disc image, as if it were a real floppy disc.

Now you can proceed as I said, with:
First copy+paste the DATA loader of MINIGRAFIK 4.02 into VICE. This is the most recent version to date. SAVE this program as "LOADER" onto a *.d64 image. RUN the program.
Now there are two files stored in the disk image file. You can check this with:

Code: Select all

LOAD"$",8 + Return

and

LIST + Return
Finally, you load, and start MINIGRAFIK thus:

Code: Select all

LOAD"MINIGRAFIK",8 + Return
RUN + Return
Then you can try the examples in this thread, using the *.d64 file to store them.
Legacy wrote:Well this thread started as me learning what a vic is and now im into assembly language basics
Some thoughts:

First. While those image files are not something innate related to the VIC, the handling of them needs be well understood if you want to use the VICE emulator efficiently.

Second. It is still not quite clear to me how proficient you are with programming at all. You are touching quite basic questions. Programming in assembly language nearly is 100% implementation oriented. If you don't have an exact idea how to implement a program, or algorithm, you're lost. While CBM BASIC still is not exactly problem oriented, you can easily test your ideas, and see if these produce a working program. It shields you in a positive way from the bare metal, as long as there are no POKE's, PEEK's, and SYS's involved.

Third. If you've gained some experience, and see that BASIC is too slow for your needs, you might consider to advance to assembly language. Take your own written BASIC programs. Think about how single BASIC commands could be rewritten in machine code (Hint: you might well need dozens, or more instructions for even a single BASIC command). Sometimes you'll have to re-formulate your program, especially when floating point arithmetic is involved.

...

Finally: I mostly wrote MINIGRAFIK to make hires graphics on the VIC-20 easily be accessible from BASIC, at usable speeds, so it isn't necessary to resort to machine language except in rare cases.

Michael
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

I still can't figure it out Mike, but thanks anyways, maybe I can just wait another couple hours for a reply in something that could be explained by a chat program in 2 minutes... anyways it was the thought that counts :)

Ive made a new image called minigrafik.d64 , paste the Loader program 4.02 onto vice 8k and run and still have runtime error!

Code: Select all

ok this is what I do:

	VICE > Settings > Vic Settings > 8K Block > Ctrl+ Alt + R

	**** CBM BASIC V2 ****
	11775 BYTES FREE
	READY.
	*
--------------------------------------------------------------------------------------------
	File > Attach Disk Image > Drive 8

	New Image

	Name: 	Minigrafik
	ID:	MG
	ext:	.d64
	
	Click > Create Image
--------------------------------------------------------------------------------------------
	File Name: minigrafik.d64	Click > Attach Image
--------------------------------------------------------------------------------------------

	VICE > Attached minigrafik.d64 to device #8

--------------------------------------------------------------------------------------------

	Edit > Paste : loader program


--------------------------------------------------------------------------------------------
	
	File > Attach Disk Image > Drive 8	

	File Name: loader.d64	Click > Attach Image	

--------------------------------------------------------------------------------------------
	
	VICE> attached loader.d64 to device #8

--------------------------------------------------------------------------------------------
	
	RUN

	?OUT OF DATA	
	ERROR IN 12
	READY.
Ok so looks like i got it right, it just wasnt pasting right, that was fun!
Last edited by Legacy on Fri Jan 30, 2009 2:03 am, edited 1 time in total.
User avatar
Mike
Herr VC
Posts: 4842
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

Legacy,

please remove the log from your previous post. It isn't necessary to quote the complete program, which already has been posted before in this thread.

Most probably the copy+paste function of VICE doesn't work properly. As I already wrote, it has only recently been added to VICE.

I'll prepare a working *.d64 image file containing MINIGRAFIK, and a few examples, and post the link.

Michael
User avatar
orion70
VICtalian
Posts: 4341
Joined: Thu Feb 02, 2006 4:45 am
Location: Piacenza, Italy
Occupation: Biologist

Post by orion70 »

Mike wrote:Most probably the copy+paste function of VICE doesn't work properly.
It often happens with DATA statements. Try listing them in VICE, and confirm each one with RETURN.
Post Reply