home *** CD-ROM | disk | FTP | other *** search
/ MikeOS 4.5 / mikeos.iso / mikeos.flp / draw.bas < prev    next >
Encoding:
BASIC Source File  |  2014-12-21  |  14.0 KB  |  835 lines

  1. rem ASCII Artist, version 3.0.0 (DRAW.BAS)
  2. rem A text drawing program for MikeOS
  3. rem Copyright (C) Joshua Beck 2002
  4. rem Mail: mikeosdeveloper@gmail.com
  5. rem Licenced under the GNU General Public Licence, see licence.txt
  6.  
  7. rem Requires the MB++ library, version 3.2.2 or greater
  8. include "mbpp.bas"
  9.  
  10. initlib:
  11.   gosub startprg
  12.   c = 4
  13.   h = 12
  14.   t = 4
  15.   z = 4
  16.   $T = "ASCII Artist"
  17.   gosub settitle
  18.   gosub anistart
  19.   gosub border
  20.   
  21. preload:
  22.   m = ramstart
  23.   n = 64100 - m
  24.  
  25.   cursor off
  26.  
  27.   for w = m to 63999
  28.     poke 0 w
  29.   next w
  30.   
  31.   gosub help_about
  32.  
  33.   if $1 = "" then goto nofile
  34.   len $1 x
  35.   if x < 5 then goto nofile
  36.   size $1
  37.   if r = 1 then goto nofile
  38.   if s > n then goto nofile
  39.   if s = 0 then goto nofile
  40.   $3 = $1
  41.   load $3 m
  42.   
  43. mainloop:
  44.   rem ***MAIN LOOP***
  45.   
  46.   e = 2
  47.   f = 3
  48.   gosub highlight_on
  49.   gosub render_image
  50.   
  51.   do
  52.     waitkey k
  53.     if k = 1 then gosub moveup
  54.     if k = 2 then gosub movedown
  55.     if k = 3 then gosub moveleft
  56.     if k = 4 then gosub moveright
  57.     if k = 18 then gosub render_image
  58.     if k = 19 then gosub savefile
  59.     if k = 27 then gosub mainmenu
  60.     if k > 31 and k < 127 then gosub inschar
  61.   loop endless
  62.   
  63.   
  64. render_image:
  65.   gosub savevar
  66.   gosub highlight_off
  67.   
  68.   ink 7
  69.   for y = 3 to 23
  70.     move 2 y
  71.     for x = 2 to 77
  72.       print " " ;
  73.     next x
  74.   next y
  75.   
  76.   string load $4 m
  77.   if $4 = "AAP" then rem
  78.   else goto invalid_file
  79.   
  80.   w = m + 4
  81.   peek v w
  82.   if v = 1 then rem
  83.   else goto invalid_file
  84.   w = m + 5
  85.   peek v w
  86.   if v = 0 then goto invalid_file
  87.   if v > 1 then goto invalid_file
  88.   w = m + 6
  89.   peekint d w
  90.   d = d + m
  91.  
  92.   w = m + 8
  93.   peek a w
  94.   if a = 0 then goto invalid_file
  95.   if a > 76 then goto invalid_file
  96.  
  97.   w = m + 9
  98.   peek b w
  99.   if b = 0 then goto invalid_file
  100.   if b > 21 then goto invalid_file
  101.  
  102.   w = m + 200
  103.   string load $4 w
  104.   $T = "ASCII Artist - " + $4
  105.   gosub settitle
  106.  
  107.   w = d
  108.   move 2 3
  109.   for y = 1 to b
  110.     j = y + 2
  111.     move 2 j
  112.     for x = 1 to a
  113.       peek v w
  114.       ink v
  115.       w = w + 1
  116.       peek v w
  117.       print chr v ;
  118.       w = w + 1
  119.     next x
  120.   next y
  121.  
  122.   gosub highlight_on
  123.   gosub loadvar
  124. return
  125.  
  126. invalid_file:
  127.   $E = "Rendering Error: Bad file format"
  128.   gosub errbox
  129.   gosub endprog
  130.   
  131. highlight_on:
  132.   if o = 1 then return
  133.   gosub savevar
  134.   move e f
  135.   curschar v
  136.   curscol j
  137.   x = j % 16
  138.   y = 15 - x
  139.   x = y
  140.   j = j / 16
  141.   y = 15 - j
  142.   j = y * 16 + x
  143.   ink j
  144.   print chr v ;
  145.   o = 1
  146.   gosub loadvar
  147. return
  148.  
  149. highlight_off:
  150.   if o = 0 then return
  151.   gosub savevar
  152.   move e f
  153.   curschar v
  154.   curscol j
  155.   x = j % 16
  156.   y = 15 - x
  157.   x = y
  158.   j = j / 16
  159.   y = 15 - j
  160.   j = y * 16 + x
  161.   ink j
  162.   print chr v ;
  163.   o = 0
  164.   gosub loadvar
  165. return
  166.   
  167. moveleft:
  168.   if e = 2 then return
  169.   gosub highlight_off
  170.   e = e - 1
  171.   gosub highlight_on
  172. return
  173.  
  174. moveright:
  175.   gosub savevar
  176.   gosub highlight_off
  177.   x = e - 1
  178.   if a = x then goto invalid_move
  179.   e = e + 1
  180.   gosub highlight_on
  181.   gosub loadvar
  182. return
  183.  
  184. moveup:
  185.   if f = 3 then return
  186.   gosub highlight_off
  187.   f = f - 1
  188.   gosub highlight_on
  189. return
  190.  
  191. movedown:
  192.   gosub savevar
  193.   gosub highlight_off
  194.   y = f - 2
  195.   if b = y then goto invalid_move
  196.   f = f + 1
  197.   gosub highlight_on
  198.   gosub loadvar
  199. return
  200.   
  201. invalid_move:
  202.   gosub highlight_on
  203.   gosub loadvar
  204. return
  205.  
  206. inschar:
  207.   gosub highlight_off
  208.   gosub savevar
  209.   move e f
  210.   gosub find_key_value
  211.   x = k % 256
  212.   ink x
  213.   x = k / 256
  214.   print chr x ;
  215.   q = k
  216.   gosub store_data
  217.   gosub highlight_on
  218.   gosub loadvar
  219. return
  220.   
  221. find_key_value:
  222.   if k < 31 then k = 0
  223.   if k > 126 then k = 0
  224.   if k = 0 then return
  225.   gosub savevar
  226.   x = m + 10
  227.   y = k - 32
  228.   y = y * 2
  229.   x = x + y
  230.   peekint k x
  231.   gosub loadvar
  232. return
  233.   
  234. set_key_value:
  235.   if k < 31 then k = 0
  236.   if k > 126 then k = 0
  237.   if k = 0 then return
  238.   gosub savevar
  239.   x = m + 10
  240.   y = k - 32
  241.   y = y * 2
  242.   x = x + y
  243.   pokeint v x
  244.   gosub loadvar
  245. return
  246.   
  247. load_data:
  248.   gosub savevar
  249.   x = e - 2
  250.   y = f - 3
  251.   j = y * a
  252.   j = j + x
  253.   j = j * 2
  254.   j = j + d
  255.   peekint q j
  256.   gosub loadvar
  257. return
  258.  
  259. store_data:
  260.   gosub savevar
  261.   x = e - 2
  262.   y = f - 3
  263.   j = y * a
  264.   j = j + x
  265.   j = j * 2
  266.   j = j + d
  267.   pokeint q j
  268.   gosub loadvar
  269. return
  270.  
  271. nofile:
  272.   $4 = "AAP"
  273.   string store $4 m
  274.   w = m + 4
  275.   poke 1 w
  276.   w = m + 5
  277.   poke 1 w
  278.   w = m + 6
  279.   pokeint 261 w
  280.   w = m + 8
  281.   poke 76 w
  282.   w = m + 9
  283.   poke 21 w
  284.   w = m + 10
  285.   gosub resetkey
  286.   w = m + 200
  287.   $4 = "Untitled Picture"
  288.   string store $4 w
  289.   w = m + 261
  290.   for x = 1 to 1596
  291.     poke 7 w
  292.     w = w + 1
  293.     poke 0 w
  294.     w = w + 1
  295.   next x
  296. goto mainloop
  297.  
  298. mainmenu:
  299.   do
  300.     $T = "             Main  Menu"
  301.     $5 = "               File"
  302.     $6 = "               Tools"
  303.     $7 = "               Keymap"
  304.     $8 = "               Help"
  305.     $9 = "               Exit"
  306.     gosub menubox
  307.     if v = 1 then gosub filemenu
  308.     if v = 2 then gosub toolsmenu
  309.     if v = 3 then gosub keymapmenu
  310.     if v = 4 then gosub helpmenu
  311.     if v = 5 then gosub endprog
  312.   loop until v = 6
  313. return
  314.  
  315. filemenu:
  316.   do
  317.     $T = "             File  Menu"
  318.     $5 = "               New"
  319.     $6 = "               Revert"
  320.     $7 = "               Load"
  321.     $8 = "               Save"
  322.     $9 = "               Save As"
  323.     gosub menubox
  324.     if v = 1 then gosub newfile
  325.     if v = 2 then gosub revert
  326.     if v = 3 then gosub loadfile
  327.     if v = 4 then gosub savefile
  328.     if v = 5 then gosub saveas
  329.   loop until v = 6
  330.   v = 0
  331. return
  332.  
  333. toolsmenu:
  334.   do
  335.     $T = "            Tools  Menu"
  336.     $5 = "               Clear"
  337.     $6 = "               Fill"
  338.     $7 = "               Invert"
  339.     $8 = "        Set all backcolour"
  340.     $9 = "        Set all forecolour"
  341.     gosub menubox
  342.     if v = 1 then gosub clear
  343.     if v = 2 then gosub fill
  344.     if v = 3 then gosub invert
  345.     if v = 4 then gosub setback
  346.     if v = 5 then gosub setfore
  347.   loop until v = 6
  348.   v = 0
  349. return
  350.  
  351. keymapmenu:
  352.   do
  353.     $T = "            Keymap  Menu"
  354.     $5 = "               Reset"
  355.     $6 = "               Load"
  356.     $7 = "               Save"
  357.     $8 = "             Change Key"
  358.     $9 = "          Set all colours"
  359.     gosub menubox
  360.     if v = 1 then gosub resetkey
  361.     if v = 2 then gosub loadkey
  362.     if v = 3 then gosub savekey
  363.     if v = 4 then gosub changekey
  364.     if v = 5 then gosub setmapcolour
  365.   loop until v = 6
  366.   v = 0
  367. return
  368.  
  369. helpmenu:
  370.   do
  371.     $T = "             Help  Menu"
  372.     $5 = "               About"
  373.     $6 = "               Basics"
  374.     $7 = "               Files"
  375.     $8 = "               Tools"
  376.     $9 = "               Keymap"
  377.     gosub menubox
  378.     if v = 1 then gosub help_about
  379.     if v = 2 then gosub help_basics
  380.     if v = 3 then gosub help_files
  381.     if v = 4 then gosub help_tools
  382.     if v = 5 then gosub help_keymap
  383.   loop until v = 6
  384.   v = 0
  385. return
  386.  
  387. newfile:
  388.   gosub savevar
  389.   $4 = "AAP"
  390.   string store $4 m
  391.   w = m + 4
  392.   poke 1 w
  393.   w = m + 5
  394.   poke 1 w
  395.   w = m + 6
  396.   pokeint 261 w
  397.   
  398.   $T = "            New File (title)"
  399.   $5 = "What do you want to call the picture?"
  400.   $6 = "Up to 35 characters."
  401.   v = 1
  402.   gosub inpbox
  403.   $4 = $I
  404.   w = m + 200
  405.   string store $4 w
  406.   
  407.   w = m + 10
  408.   for x = 32 to 126
  409.     poke 7 w
  410.     w = w + 1
  411.     poke x w
  412.     w = w + 1
  413.   next x
  414.  
  415.   w = m + 261
  416.   for x = 1 to 3192
  417.     poke 0 w
  418.     w = w + 1
  419.   next x
  420.   
  421.   $T = "            New File (size)"
  422.   $5 = "How many columns?"
  423.   $6 = "How many rows?"
  424.   v = 0
  425.   gosub dinbox
  426.   w = m + 8
  427.   pokeint a w
  428.   w = m + 9
  429.   pokeint b w
  430.   
  431.   gosub loadvar
  432.   
  433.   gosub render_image
  434.   $3 = "" 
  435. return
  436.  
  437. revert:
  438.   if $3 = "" then return
  439.   load $3 m
  440.   gosub render_image
  441. return
  442.  
  443. loadfile:
  444.   $T = "               Load File"
  445.   $5 = "Which file do you want to load?"
  446.   $6 = "8.3 filenames only, i.e. foo.aap"
  447.   v = 1
  448.   gosub inpbox
  449.   $4 = $I
  450.  
  451.   size $4
  452.   if r = 1 then $E = "File Load Error: Invalid Filename"
  453.   if r = 1 then goto errbox
  454.   if s = 0 then $E = "File Load Error: Blank File"
  455.   if s = 0 then goto errbox
  456.   if s > n then $E = "File Load Error: Not enough memory"
  457.   if s > n then goto errbox
  458.   load $4 m
  459.   $3 = $4
  460.  
  461.   string load $4 m
  462.   if $4 = "AAP" then rem
  463.   else $E = "File Load Error: Incorrect Filetype"
  464.   else goto errbox
  465.   w = m + 4
  466.   peek v w
  467.   if v = 0 goto badformat
  468.   if v > 1 then goto futureversion
  469.   w = m + 5
  470.   if v = 0 then goto badformat
  471.   if v > 1 then goto badformat
  472.   w = m + 8
  473.   peek v w
  474.   if v > 76 then $E = "File Test Error: Not enough screen space"
  475.   if v > 76 then goto errbox
  476.   w = m + 9
  477.   peek v w
  478.   if v > 21 then $E = "File Test Error: Not enough screen space"
  479.   if v > 21 then goto errbox
  480.  
  481. image_okay:
  482.   gosub render_image
  483.   
  484.   gosub highlight_off
  485.   e = 2
  486.   f = 3
  487.   gosub highlight_on
  488. return
  489.  
  490. badformat:
  491.   $E = "File Test Error: Bad File Format"
  492.   goto errbox
  493.   
  494. futureversion:
  495.   $T = "               Load File"
  496.   $5 = ""
  497.   $6 = "This file appears to have been created"
  498.   $7 = "with a later version of this program."
  499.   $8 = "Try to load anyway?"
  500.   $9 = ""
  501.   gosub askbox
  502.   if v = 1 then goto image_okay
  503. return
  504.  
  505. savefile:
  506.   if $3 = "" then goto saveas
  507.   delete $3
  508.   
  509.   w = m + 6
  510.   peekint v w
  511.   j = a * b * 2 + v
  512.   save $3 m j
  513.   if r > 0 then $3 = ""
  514.   if r > 0 then $E = "File Save Error: Disk operation failed"
  515.   if r > 0 then goto errbox
  516. return
  517.  
  518. saveas:
  519.   $T = "            Save File As..."
  520.   $5 = "What filename do you want to save as?"
  521.   $6 = "8.3 filenames only, i.e. foo.aap"
  522.   v = 1
  523.   gosub inpbox
  524.   $3 = $I
  525. goto savefile
  526.  
  527. clear:
  528.   gosub savevar
  529.   w = d
  530.   for x = 1 to 1596
  531.     poke 7 w
  532.     w = w + 1
  533.     poke 0 w
  534.     w = w + 1
  535.   next x
  536.   
  537.   gosub render_image
  538.   gosub loadvar
  539. return
  540.  
  541. fill:
  542.   gosub savevar
  543.   $T = "             Fill Image"
  544.   $5 = "What character do you want to use?"
  545.   $6 = "Must be between 0-255"
  546.   v = 0
  547.   gosub inpbox
  548.   w = d + 1
  549.   for x = 1 to 1596
  550.     poke v w
  551.     w = w + 2
  552.   next x
  553.   
  554.   gosub render_image
  555.   gosub loadvar
  556. return
  557.  
  558. setback:
  559.   gosub savevar
  560.   $T = "         Background Colour"
  561.   $5 = "What colour do you want to set?"
  562.   $6 = "Must be between 0-15"
  563.   v = 0
  564.   gosub inpbox
  565.   w = d
  566.   j = v * 16
  567.   for x = 1 to 1596
  568.     peek v w
  569.     v = v % 16
  570.     v = v + j
  571.     poke v w
  572.     w = w + 2
  573.   next x
  574.   
  575.   gosub render_image
  576.   gosub loadvar
  577. return
  578.  
  579. setfore:
  580.   gosub savevar
  581.   $T = "         Foreground Colour"
  582.   $5 = "What colour do you want to set?"
  583.   $6 = "Must be between 0-15"
  584.   v = 0
  585.   gosub inpbox
  586.   w = d
  587.   j = v
  588.   for x = 1 to 1596
  589.     peek v w
  590.     v = v / 16
  591.     v = v * 16
  592.     v = v + j
  593.     poke v w
  594.     w = w + 2
  595.   next x
  596.   
  597.   gosub render_image
  598.   gosub loadvar
  599. return
  600.  
  601. invert:
  602.   gosub savevar
  603.   w = d
  604.   for x = 1 to 1596
  605.     peek v w
  606.     j = v / 16
  607.     y = j
  608.     j = j * 16
  609.     v = v - j
  610.     j = 15 - y
  611.     j = j * 16
  612.     v = v + j
  613.     
  614.     j = v % 16
  615.     y = j
  616.     v = v - j
  617.     j = 15 - y
  618.     v = v + j
  619.     
  620.     poke v w
  621.     w = w + 2
  622.   next x
  623.   
  624.   gosub render_image
  625.   gosub loadvar
  626. return
  627.  
  628. resetkey:
  629.   gosub savevar
  630.   w = m + 10
  631.   for x = 32 to 126
  632.     poke 7 w
  633.     w = w + 1
  634.     poke x w
  635.     w = w + 1
  636.   next x
  637.   w = m + 200
  638.   gosub loadvar
  639. return
  640.   
  641. loadkey:
  642.   $T = "           Load Keymap"
  643.   $5 = "Which keymap do you want to load?"
  644.   $6 = "8.3 filenames only, i.e. foo.map"
  645.   v = 1
  646.   gosub inpbox
  647.   $4 = $I
  648.   
  649.   size $4
  650.   if r = 1 then $E = "Load Keymap: File not found"
  651.   if r = 1 then goto errbox
  652.   if s > 200 then $E = "Load Keymap: Incorrect size"
  653.   if s > 200 then goto errbox
  654.  
  655.   w = m + 3500
  656.   load $4 w
  657.   
  658.   string load $4 w
  659.   if $4 = "AAP" then rem
  660.   else goto badformat
  661.   w = w + 4
  662.   peek v w
  663.   if v = 1 then rem
  664.   else goto badformat
  665.   w = w + 1
  666.   peek v w
  667.   if v = 2 then rem
  668.   else goto badformat
  669.   
  670.   w = w + 1
  671.   j = m + 10
  672.   for x = 1 to 190
  673.     peek v w
  674.     poke v j
  675.     w = w + 1
  676.     j = j + 1
  677.   next x
  678.   v = 0
  679. return
  680.   
  681. badformat:
  682.   $E = "Load Keymap: Bad format"
  683.   goto errbox
  684.   
  685. savekey:
  686.   $T = "           Save Keymap"
  687.   $5 = "What do you want to call the keymap?"
  688.   $6 = "8.3 filenames only, i.e. foo.map"
  689.   v = 1
  690.   gosub inpbox
  691.  
  692.   w = m + 3500
  693.   $4 = "AAP"
  694.   string store $4 w
  695.   w = w + 4
  696.   poke 1 w
  697.   w = w + 1
  698.   poke 2 w
  699.  
  700.   w = w + 1
  701.   j = m + 10
  702.   for x = 1 to 190
  703.     peek v j
  704.     poke v w
  705.     j = j + 1
  706.     w = w + 1
  707.   next x
  708.   
  709.   w = m + 3500
  710.   $4 = $I
  711.   save $4 w 196
  712.   v = 0
  713. return
  714.   
  715. changekey:
  716.   gosub savevar
  717.   x = a
  718.   y = b
  719.   $T = "          Change Key"
  720.   $5 = "Enter the ASCII value of the key"
  721.   $6 = "Enter the new output value"
  722.   v = 0
  723.   gosub dinbox
  724.  
  725.   k = a
  726.   w = b * 256
  727.   
  728.   $T = "          Change Key"
  729.   $5 = "Enter the background colour"
  730.   $6 = "Enter the foreground colour"
  731.   v = 0
  732.   gosub dinbox
  733.   
  734.   j = a * 16
  735.   j = j + b
  736.   v = j + w
  737.   gosub set_key_value
  738.   
  739.   a = x
  740.   b = y
  741.   gosub loadvar
  742.   k = 0
  743. return
  744.  
  745. setmapcolour:
  746.   gosub savevar
  747.   $T = "         Set Background"
  748.   $5 = "What colour do you want to use for"
  749.   $6 = "the key map background (0-15)?"
  750.   v = 0
  751.   gosub inpbox
  752.   if v > 15 then v = 0
  753.  
  754.   w = m + 10
  755.   for x = 1 to 95
  756.     peek y w
  757.     j = y / 16
  758.     j = j * 16
  759.     y = y - j
  760.     j = v * 16
  761.     y = y + j
  762.     poke y w
  763.     w = w + 2
  764.   next x
  765.  
  766.   $T = "         Set Foreground"
  767.   $5 = "What colour do you want to use for"
  768.   $6 = "the key map foreground (0-15)?"
  769.   v = 0
  770.   gosub inpbox
  771.   if v > 15 then v = 7
  772.   
  773.   w = m + 10
  774.   for x = 1 to 95
  775.     peek y w
  776.     j = y % 16
  777.     y = y - j
  778.     y = y + v
  779.     poke y w
  780.     w = w + 2
  781.   next x
  782.   gosub loadvar
  783. return
  784.     
  785. help_about:
  786.   $T = "              About"
  787.   $5 = "ASCII Artist, version 3.0.0"
  788.   $6 = "Copyright (C) Joshua Beck 2012"
  789.   $7 = "Email: mikeosdeveloper@gmail.com"
  790.   $8 = "Licenced under the GNU GPL v3"
  791.   $9 = "Uses the MB++ library, version 3.2.2"
  792.   gosub mesbox
  793. return
  794.  
  795. help_basics:
  796.   $T = "              Basics"
  797.   $5 = "Use the arrow keys to move around."
  798.   $6 = "Letter, word and symbol keys will"
  799.   $7 = "create their corrosponding character"
  800.   $8 = "Use escape to bring up the main menu"
  801.   $9 = "and to exit from menus."
  802.   gosub mesbox
  803. return
  804.  
  805. help_tools:
  806.   $T = "              Tools"
  807.   $5 = "The tools menu helps you make large"
  808.   $6 = "scale modifications to the picture."
  809.   $7 = "You can clear the picture, fill it"
  810.   $8 = "with a character, invert it and"
  811.   $9 = "change the all the colours."
  812.   gosub mesbox
  813. return
  814.  
  815. help_keymap:
  816.   $T = "             Keymap"
  817.   $5 = "Each printable key is mapped to a"
  818.   $6 = "character by default this character"
  819.   $7 = "corrosponds to the one on the key"
  820.   $8 = "and uses the colour white but you"
  821.   $9 = "can customize these values."
  822.   gosub mesbox
  823. return
  824.  
  825. help_files:
  826.   $T = "              Files"
  827.   $5 = "ASCII Artist use its own file format."
  828.   $6 = "This supports titles, colour, custom"
  829.   $7 = "size, keymaps, etc. You can save"
  830.   $8 = "your pictures in the file menu and"
  831.   $9 = "custom key maps in the keymap menu."
  832.   gosub mesbox
  833. return
  834.  
  835.