320x200 - a CGA emulator for VIC-20! (+35K RAM req'd)

Basic and Machine Language

Moderator: Moderators

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

320x200 - a CGA emulator for VIC-20! (+35K RAM req'd)

Post by Mike »

Hi, y'all!

Here's a program to display a bitmap of 320x200 pixels in 4 colours on the VIC-20 (download): :mrgreen:

Code: Select all

10 AD=PEEK(55)+256*PEEK(56):IFAD<>12376THENPOKE55,88:POKE56,48:CLR
11 IFAD=0THENFORT=12376TO12700:READA:POKET,A:NEXT:SYS12376:AD=12376
12 DN=PEEK(186):INPUT"FILE";N$:OPEN2,DN,2,N$+",S,R":GET#2,A$,B$:CLOSE2
13 A=ASC(A$+CHR$(.)):SYS57809N$+",S",DN,0:POKE780,0:POKE781,88:POKE782,48:SYS65493
14 POKE646,AAND15:POKE36878,AAND240:POKE36879,ASC(B$+CHR$(.)):@ON:@CLR:X=0:Y=0:P=-1
15 IFPTHENP=0:POKE251,ADAND255:POKE252,AD/256:SYS1024
16 GETA$:IFA$=""THEN16
17 IFA$="{LEFT}"ANDX>0THENX=X-1:AD=AD-200:P=-1
18 IFA$="{RIGHT}"ANDX<60THENX=X+1:AD=AD+200:P=-1
19 IFA$="{UP}"ANDY>0THENY=Y-1:AD=AD-4:P=-1
20 IFA$="{DOWN}"ANDY<34THENY=Y+1:AD=AD+4:P=-1
21 IFA$="S"THENOPEN15,DN,15,"S0:SCRAPFILE":CLOSE15:@SAVE"SCRAPFILE",DN
22 IFA$=" "THEN:@RETURN:END
23 GOTO15
24 :
25 DATA 169,0,141,146,49,133,251,169,64,141,147,49,169,17,133,252,162,20,169,160,32,145
26 DATA 49,169,0,32,145,49,160,64,169,177,32,145,49,169,251,32,145,49,169,200,32,145,49
27 DATA 169,141,32,145,49,165,251,32,145,49,165,252,32,145,49,32,138,49,169,141,32,145
28 DATA 49,165,251,32,145,49,165,252,32,145,49,32,138,49,169,141,32,145,49,165,251,32
29 DATA 145,49,165,252,32,145,49,32,138,49,136,208,184,169,24,32,145,49,169,165,32,145
30 DATA 49,169,251,32,145,49,169,105,32,145,49,169,200,32,145,49,169,133,32,145,49,169
31 DATA 251,32,145,49,169,165,32,145,49,169,252,32,145,49,169,105,32,145,49,169,0,32
32 DATA 145,49,169,133,32,145,49,169,252,32,145,49,202,240,3,76,106,48,169,0,133,251
33 DATA 169,64,133,252,169,0,133,253,169,4,133,254,162,252,160,15,32,110,49,169,76,141
34 DATA 252,15,169,216,141,253,15,169,110,141,254,15,169,33,133,251,169,93,133,252,169
35 DATA 0,133,253,169,160,133,254,162,254,160,191,32,110,49,169,96,141,254,191,169,252
36 DATA 133,251,169,75,133,252,169,216,133,253,169,110,133,254,162,253,160,127,32,110
37 DATA 49,169,76,141,253,127,169,0,141,254,127,169,160,141,255,127,96,152,72,160,0,177
38 DATA 251,32,138,49,145,253,230,253,208,2,230,254,104,168,228,253,208,233,196,254,208
39 DATA 229,96,230,251,208,2,230,252,96,141,255,255,238,146,49,208,3,238,147,49,96
40 :
41 REM ** CGA PAN VIEWER WRITTEN 2016-11-16 BY MICHAEL KIRCHER
The program was inspired by a posting of mine in the "MINIPAINT 1.2" thread. I pondered for myself for some days how much it would take to get that picture there on display on the VIC-20.

+35K RAM are required: yes, that means +24K in BLK1..3, +8K in BLK5 *and* +3K in RAM1..3! Decompress the *.zip archive and run the file "BOOT". The program lets you pan a view into the whole picture with the cursor keys. The display is zoomed, so the pixels do have a square aspect ratio (about perfect for NTSC, only slightly elongated for PAL). With "S", the current view is saved as MINIGRAFIK/MINIPAINT picture file. SPACE returns you to BASIC.

I have included two example pictures, PCPAINT1 and CECILE. Just enter their name in the "FILE?" prompt. These files are 16002 bytes in size, the first 2 bytes hold palette information, the following 16000 bytes contain the bitmap in column-major order. The payload then is loaded to address $3058 in RAM.

This is still a work in progress, and a converter from 4 colour *.ppm files is in the works.

Enjoy!

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

Re: 320x200 - a CGA emulator for VIC-20! (+35K RAM req'd)

Post by GreyGhost »

This is pretty neat. I was expecting the usual April Fools gag. lol. The scrolling is very fast. I look forward to seeing what becomes of this.
Rob
Bobbi
Vic 20 Afficionado
Posts: 355
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: 320x200 - a CGA emulator for VIC-20! (+35K RAM req'd)

Post by Bobbi »

I am 3096 bytes short!! Damn!
User avatar
orion70
VICtalian
Posts: 4337
Joined: Thu Feb 02, 2006 4:45 am
Location: Piacenza, Italy
Occupation: Biologist

Re: 320x200 - a CGA emulator for VIC-20! (+35K RAM req'd)

Post by orion70 »

Wow! I just ignored your post in the first place, given the peculiar date of publication :).
Thanks for that. Can't wait for the ppm converter, so that I can play with some "classic" CGA screenshots.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: 320x200 - a CGA emulator for VIC-20! (+35K RAM req'd)

Post by Mike »

Mike wrote:This is still a work in progress, and a converter from 4 colour *.ppm files is in the works.
Found time this evening to give it a try. Here's a new example picture (download) ... :mrgreen:

The converter takes a full-colour 320x200 *.ppm file and does a full optimization for the best 4 colour palette out of the 16 available colours. That's a search space of 'just' 1302 combinations.

Cheers,

Michael
User avatar
tokra
Vic 20 Scientist
Posts: 1120
Joined: Tue Apr 27, 2010 5:32 pm
Location: Scheessel, Germany

Re: 320x200 - a CGA emulator for VIC-20! (+35K RAM req'd)

Post by tokra »

Neat! This would have been a good starting point for my "VIC Hunt"-picture which uses exactly the same "pixel"-size (2 wide, 3 high) :D
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: 320x200 - a CGA emulator for VIC-20! (+35K RAM req'd)

Post by Mike »

tokra wrote:This would have been a good starting point for my "VIC Hunt"-picture [...]
Though it becomes quite cumbersome and confusing to edit the picture in the zoomed view of both fcbpaint and MINIPAINT. Starting from this converted picture ...

Image

... you'll only ever get to see (and save as scrapfile) a view like this ...

Image

... which will look like this when edited in MINIPAINT (it's the right eye of the inkling girl), ...

Image

... or like this in fcbpaint (just the eye's pupil). :shock:

Image

I've put "inkling.fcb" (for fcbpaint) and "inkling.prg" (for MINIPAINT) here for download. "inkling.prg" was saved straight as scrapfile from the CGA panning viewer, and in turn converted to "inkling.fcb" with MG2FCB.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: 320x200 - a CGA emulator for VIC-20! (+35K RAM req'd)

Post by Mike »

Mike wrote:[...] a converter from 4 colour *.ppm files is in the works.
Here we go (download):

When you double-click 'ppm2cga.cmd', the *.exe will quantize the file 'input.ppm' (strictly 320x200 pixels and a 24 bpp *.ppm file) and write the files 'result.ppm' (preview on PC) and 'result.seq' (for use by the panning viewer in the OP). If you change the filenames in the command line, neither the input file nor the preview file (1st and 2nd parameters) include the *.ppm extension - this is added internally!

The bundled executable requires a 64 bit Windows. Source is included for those who want to have some insight and/or want to compile the *.exe for themselves. The converter should compile on pretty much everything that has a C compiler. :)

Cheers,

Michael

P.S. if you want to use another permutation of the physical to logical colour mapping for SCRAPFILE pictures saved from the CGA panning viewer, take a look at the REMAP tool set in the MG batch suite.
mamejay
Vic 20 Newbie
Posts: 8
Joined: Tue Jan 08, 2019 7:04 pm
Location: Melbourne, Australia

Re: 320x200 - a CGA emulator for VIC-20! (+35K RAM req'd)

Post by mamejay »

Hi Mike,
I have built Ruud's 35k RAM expansion and have been doing some testing.
I can't seem to get the 320x200 to work. I have run your memory test program and the initial tests with all banks on is showing ram in all locations.

Should your program work with Ruud's memory expansion? http://www.baltissen.org/newhtm/memv20.htm

I am loading it from a SD2IEC

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

Re: 320x200 - a CGA emulator for VIC-20! (+35K RAM req'd)

Post by Mike »

A more detailed problem description would be helpful.
mamejay wrote:Should your program work with Ruud's memory expansion?
Yes. *Any* RAM expansion that provides +35K as per the description in the OP will work.
I am loading it from a SD2IEC
So do I, but the exact type of drive really doesn't matter. The program will also work, if you transfer the *.zip file's content onto a real disk and run it from a disk drive (in that case, be sure the picture files are saved with a SEQ file type).
I can't seem to get the 320x200 to work.
If you proceed like given in the OP, at which point does the output of the program differ from expected behaviour?
mamejay
Vic 20 Newbie
Posts: 8
Joined: Tue Jan 08, 2019 7:04 pm
Location: Melbourne, Australia

Re: 320x200 - a CGA emulator for VIC-20! (+35K RAM req'd)

Post by mamejay »

Hi Mike,

Basically I run your program and select the image file. After sometime I am throw back out to basic with a flashing cursor.
At the moment I have all dip switches enabled except for the write-protect switch.
I tested your program in VICE and all is working as expected.
I will give it another go tonight after work. I will also run your memory test program completely and see if any errors occur.
mamejay
Vic 20 Newbie
Posts: 8
Joined: Tue Jan 08, 2019 7:04 pm
Location: Melbourne, Australia

Re: 320x200 - a CGA emulator for VIC-20! (+35K RAM req'd)

Post by mamejay »

Hi Mike,
OK did more tests. Thanks for the heads up about naming the files correctly. I created a D64 image that did not have SEQ extension.
I just moved the files to a folder and not in a D64 image and it loaded perfectly VIA the SD2IEC.

Excellent my ram expansion is working.
Thanks for the great test.
Post Reply