#################################
# BASIC Tenliners Contest 2017  #
#                               #
# iNVERSO64 Icon Maker          #
# (c) 2017 Roman Werner @romwer #
# email: roman.werner@gmail.com #
#################################

The iNVERSO64 Icon Maker is a supplement to the iNVERSO64 puzzle game in order to create your own pictures.
As a nice side effect the Icon Maker can also be used to learn about bit combinations and what byte numbers they produce. After all it's also another tenliner.

Here is a small collection of pictures/data sets I have put together for you (the first 3 are already in the game):

data24,20,26,22,114,226,14,28:rem Music Note
data66,189,90,102,194,66,188,196:rem Cute Pug
data231,195,129,36,0,195,129,90:rem Invader
data24,36,228,61,67,157,129,126:rem Duck
data247,228,212,215,231,54,0,129:rem Sailing Boat
data147,239,135,98,96,131,87,129:rem Helicopter
data231,219,223,239,195,189,189,0:rem Captain Hook
data52,102,215,227,128,193,193,193:rem Rabbit in a top hat after a magic trick
data255,153,31,144,4,112,114,114:rem Man sitting in front of a Commodore 1702 monitor playing iNVERSO on a real C64 (breadbox model) ;)

For your interest here are just some bit combination examples:
---------------------------------
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | = bit position 0-7 in a byte
---------------------------------
|128| 64| 32| 16| 8 | 4 | 2 | 1 | = decimal value representation for each bit 0-7
---------------------------------
  1   1   0   0   0   0   0   0   = 192
  0   0   1   0   0   1   0   1   =  37
  0   0   0   0   0   0   1   1   =   3

When working with the 8-Bit computers you will need to deal with these bit combinations a lot. So it is good practice to play around and get familiar with. :)


Keyboard Control:
=================
<CRSR keys>* = Move the dark gray cursor around the tileset
<space>      = set or clear a tile
<return>     = Invert tileset (pictures look different when inverted. Just try out what looks best)
<arrow left> = This is the top left key on the c64 keyboard or generally the key left from the '1' key.
               Press this when you finished with your picture to produce an 8 byte data set or
               if you want to restart with en empty tileset (in that case type 'RUN' + <return>).

The 8-byte data set can be copied - or simply write the numbers down to a sheet of paper - and be used in the iNVERSO64 puzzle game. You can replace the existing 3 pictures (look for the three existing 8-byte data sets) or add more data sets to the code. In the latter case don't forget to increase the picture counter 'q' in the statement: ifq=3thenrestore:q=0. So if you have added 2 more 8-byte data sets in line 10 and higher, the statement should be changed to: ifq=5thenrestore:q=0. Simple as that.

*Note: if you would rather have the WASD control scheme to move the cursor around then just replace the following ASCII codes in the code:
Change k=145 (Up)    to k=87 (W)
Change k=157 (Left)  to k=65 (A)
Change k=17  (Down)  to k=83 (S)
Change k=29  (Right) to k=68 (D)


Tool Requirements:
==================
- C64/C128* with BASIC 2.0 runtime environment (or compatible)

*Also playable on Windows/MacOS/iOS/Android (C64 Emulator required)


Starting in VICE: C64 emulator (http://vice-emu.sourceforge.net/):
==================================================================
Start the emulator and then drag and drop the "inverso64iconmaker.prg" into the VICE window.
-or-
Load the program with the command: load "inverso64iconmaker.prg",8
Then start the program with:       run


iNVERSO64 Icon Maker BASIC program code:
========================================
0v=53280:pokev,6:j=128:r=58640:z=214:t$="{reverse on}O{cm y}{down}{left}{left}{cm g} {up}{reverse off}{light blue}":s$(0)="{black}"+t$:s$(1)="{red}"+t$
1print"{clear}"spc(15)"inverso 64":printspc(15)"icon maker{down}":fory=0to7:gosub7:printspc(28)b:n(y)=b:next:y=w
2pokez,y*2+3:sysr:printtab(x*2+12)"{dark gray}"t$
3geta$:on-(a$="")goto3:k=asc(a$):d=1:e=0:on-(k=17)goto5:d=-1:on-(k=145)goto5:d=0:e=1
4on-(k=29)goto5:e=-1:on-(k=157)goto5:on-(k=32)goto6:on-(k=13)goto8:on-(k=95)goto9:goto3
5gosub7:y=y+daN7:x=x+eaN7:gO2
6m(x,y)=1-m(x,y):gosub7:printspc(28)"{reverse off}"b"{left}  ":n(y)=b:goto2
7pokez,y*2+3:sysr:b=0:i=j:forc=0to7:o=m(c,y):printtab(12)s$(o);:b=bor(i*o):i=i/2:next:print:return
8fora=0to7:forb=0to7:m(a,b)=1-m(a,b):next:next:w=y:goto1
9print"{up}"tab(x*2+12)s$(m(x,y)):pokez,20:sysr:print"data";:fori=0to6:printn(i)"{left},";:next:printn(7)

Tip: Copy/paste the program-Code into CBM prg Studio (http://www.ajordison.co.uk/).
There you can see the commands in nice color highlighting and you can directly execute the game in an emulator of your choice.


iNVERSO64 Icon Maker Tenliner explained (000=row 0/100=row 1/...):
==================================================================
000 v=53280: rem VIC Frame-Color address
010 pokev,6: rem  set Frame-Color to blue
020 j=128: rem the decimal value of highest bit (7) in a byte
030 r=58640: rem kernal rom sys address to set cursor
040 z=214: rem poke address to set row
050 t$="{reverse on}O{cm y}{down}{left}{left}{cm g} {up}{reverse off}{light blue}": rem tile
060 s$(0)="{black}"+t$: rem black tile
070 s$(1)="{red}"+t$: rem red tile
100 print"{clear}"spc(15)"inverso 64": rem show title
110 printspc(15)"icon maker{down}": rem show subtitle
120 fory=0to7: rem for each row...
130 gosub700: rem print tiles
140 printspc(28)b: rem print decimal value of bit combination
150 n(y)=b: rem store in array (to later print 8-byte data set)
160 next: rem do this for all 8 rows 
170 y=w: rem restore current y position
200 pokez,y*2+3: rem set cursor at current y line (plus 3 lines from top)
210 sysr: rem call routine to set cursor (column position does not matter)
220 printtab(x*2+12)"{dark gray}"t$: rem print dark gray cursor
300 geta$: rem read next key press
310 on-(a$="")goto300: rem no key then wait for next key press
320 k=asc(a$): rem get ascii value from string. Uses less characters this way.
330 d=1: rem set y direction to 1 (=down)
340 e=0: rem set x direction to 0
350 on-(k=17)goto500: rem cursor down key?
360 d=-1: rem set y direction to -1 (=up)
370 on-(k=145)goto500: rem cursor up key?
380 d=0: rem set y direction to 0
390 e=1: rem set x direction to 1 (=right)
400 on-(k=29)goto500: rem cursor right key?
410 e=-1: rem set x direction to -1 (=left)
420 on-(k=157)goto500: rem cursor left key?
430 on-(k=32)goto600: rem space key?
440 on-(k=13)goto800: rem return key?
450 on-(k=95)goto900: rem arrow left key?
460 goto300: rem wait for next key press
500 gosub700: rem print all 8 tiles in row (removes gray cursor)
510 y=y+dand7: rem add y direction (if d is 8 then 'and7' will make y = 0)
520 x=x+eand7: rem add x direction (if e is 8 then 'and7' will make x = 0)
530 goto200: rem print cursor at new position
600 m(x,y)=1-m(x,y): rem inverse current tile in 8x8 matrix
610 gosub700: rem print all 8 tiles in row (removes gray cursor)
620 printspc(28)"{reverse off}"b"{left}  ": rem print new bit combination value
630 n(y)=b: rem store in array (to later print 8-byte data set)
640 goto200: rem print cursor again at current position
700 pokez,y*2+3: rem set cursor at current y line (plus 3 lines from top)
710 sysr: rem call routine to set cursor (column position does not matter)
720 b=0: rem reset total value for bit combinations
730 i=j: rem assign highest decimal value (128)
740 forc=0to7: rem for each bit in byte...
750 o=m(c,y): rem get tile value (0 or 1)
760 printtab(12)s$(o);: rem print red or black tile
770 b=bor(i*o): rem set bit value if o is 1
780 i=i/2: rem calculate next bit value (128/2=64,64/2=32,...)
790 next: rem do this for all 8 bits
794 print: rem to make the cursor position go down a line
796 return: rem return and continue with the code following gosub700
800 fora=0to7: rem for each row in tileset...
810 forb=0to7: rem for each tile in row...
820 m(a,b)=1-m(a,b): rem switch value = make 0 to 1 and 1 to 0.
830 next: rem do this for remaining tiles
840 next: rem do this for remaining rows
850 w=y: rem backup current cursor y position (would be lost otherwise)
860 goto100: rem reprint complete tileset (now inversed)
900 print"{up}"tab(x*2+12)s$(m(x,y)): rem restore tile under gray cursor 
910 pokez,20: rem place cursor in row 20
920 sysr: rem call routine to set cursor
930 print"data";: rem print data statement
940 fori=0to6: rem for the first 7 rows...
950 printn(i)"{left},";: rem print byte value and a comma
960 next: rem do this for all remaining rows
970 printn(7): rem then print the byte value of last row (without comma)
