Home » Recent acquisitions » Acorn ADFS disks » adfs_AcornUser_199609.adf » Regulars » StarInfo/Lurcock/!SpiroLat/c/main

StarInfo/Lurcock/!SpiroLat/c/main

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Recent acquisitions » Acorn ADFS disks » adfs_AcornUser_199609.adf » Regulars
Filename: StarInfo/Lurcock/!SpiroLat/c/main
Read OK:
File size: 12FE bytes
Load address: 0000
Exec address: 0000
File contents
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "OS:toolbox.h"
#include "OS:messagetrans.h"
#include "OS:window.h"
#include "OS:saveas.h"
#include "OS:numberrange.h"
#include "OS:writablefield.h"
#include "OS:drawfile.h"
#include "OS:event.h"

#include "events.h"
#include "spiro.h"
#include "main.h"

/* This was compiled with OSLib release 5.1. To recompile you will also need
   the eventlib header (h.event) from the OSLib examples directory.
*/

messagetrans_control_block message_block;
toolbox_block  		event_id_block;
int       		quit = 0;
drawfile_diagram 	*draw_file;
int 			draw_size, draw_max;
os_trfm			draw_trfm;
toolbox_o		saveas_id,display_id;

bool redraw_window(wimp_event_no event_code, wimp_block *event,toolbox_block *id_block,void *handle)
{
   int height;
   bool more;
   wimp_window_state state;
   wimp_draw block;
   os_box extent;

   state.w = event->redraw.w;
   block.w = event->redraw.w;
   wimp_get_window_state(&state);
   window_get_extent(0,id_block->this_obj,&extent);
   height = extent.y1 -extent.y0;
   draw_trfm.entries[2][0] = (state.visible.x0 - state.xscroll) *256;
   draw_trfm.entries[2][1] = (state.visible.y1 -height -state.yscroll) *256;

   more = wimp_redraw_window(&block);
   while (more)
   {
      wimp_set_colour(128);
      os_writec(os_VDU_CLG);
      drawfile_render(0, draw_file, draw_size, &draw_trfm,
      		      &(block.box), 0);
      more = wimp_get_rectangle(&block);
   }

   return 1;
}

bool update_drawfile(bits event_code, toolbox_action *event, toolbox_block *id_block, void *handle)
{
  int order,scale,angle,i,xsize,ysize;
  double xscale,yscale;
  os_box box;
  char turn[65];

  order = numberrange_get_value(0,id_block->this_obj,4);
  if (order>64) order = 64;
  if (order<1) order = 1;
  numberrange_set_value(0,id_block->this_obj,4,order);
  /* The reason for always setting the value, even if the order
     seems to be within the bounds, is that numberrange_get_value sometimes
     returns a value different to that which is visible in the icon!
     This only seems to occur in writables where something outside the
     bounds has been typed in.
  */
  scale = numberrange_get_value(0,id_block->this_obj,5);
  angle = numberrange_get_value(0,id_block->this_obj,6);
  if (angle>179) angle = 179;
  if (angle<1) angle = 1;
  numberrange_set_value(0,id_block->this_obj,6,angle);
  writablefield_get_value(0,id_block->this_obj,7,turn,65);

  for(i=0;i<65;i++) {
    if((turn[i]=='L')||(turn[i]=='l')||(turn[i]=='<')) turn[i] = 1;
    else turn[i]=0;
  }

  draw_size = build_draw_file(order,turn,angle,scale);
  shift_draw_file(draw_file);
  saveas_set_data_address(0,saveas_id,(byte *)draw_file,draw_size,0,0);
  saveas_set_file_size(0,saveas_id,draw_size);

  xsize = draw_file->bbox.x1 - draw_file->bbox.x0;
  ysize = draw_file->bbox.y1 - draw_file->bbox.y0;
  if (xsize<ysize) xsize = ysize;
  else ysize = xsize;
  window_get_extent(0,display_id,&box);
  if (xsize!=0) {
    xscale = 256 * (box.x1);
    yscale = 256 * (abs(box.y0));
    xscale/= xsize;
    yscale/= ysize;
  }
  else {
    xscale = 1;
    yscale = 1;
  }
  draw_trfm.entries[0][0] = (int) (1<<16) * xscale;
  draw_trfm.entries[1][1] = (int) (1<<16) * yscale;
  window_force_redraw(0,display_id,&box);

  return 1;
}

int finalisation(bits event_code, toolbox_action *event, toolbox_block *id_block, void *handle)
{
  quit = 1;
  return 1;
}

int attach_handlers(bits event_code,toolbox_action *event,toolbox_block *id_block, void *handle)
{
  if (!strcmp(event->data.created.name, "Iconbar")) {
    event_register_toolbox_handler(event_ANY,menu_quit_event,finalisation,0);
    event_register_toolbox_handler(event_ANY,update_drawfile_event,
    				   update_drawfile,NULL);
    event_register_wimp_handler(event_ANY,wimp_REDRAW_WINDOW_REQUEST,
    				redraw_window,NULL);
  }
  if (!strcmp(event->data.created.name,"SaveAs"))
    saveas_id = id_block->this_obj;
  if (!strcmp(event->data.created.name,"Display"))
    display_id=id_block->this_obj;
  return 1;
}

bool msgquit_handler(wimp_message *message, void *handle)
{
  quit = 1;
  return 1;
}

void initialise(void)
{
  wimp_poll_flags mask;

  event_initialise(&event_id_block);
  mask = wimp_MASK_NULL;
  event_set_mask(mask);

  event_register_toolbox_handler(event_ANY, action_OBJECT_AUTO_CREATED,
  				 attach_handlers,NULL);
  event_register_message_handler(message_QUIT, msgquit_handler, NULL);

  toolbox_initialise(0,310, (wimp_message_list *)wimp_messages,
  (toolbox_action_list *)toolbox_events, "<SpiroLat$Dir>", &message_block,
  &event_id_block, 0, 0);

  draw_max  = INITIAL_SIZE;
  draw_file = malloc(draw_max);
  draw_size = init_draw_file(draw_file);
}

int main(int argc, char *argv[])
{
  wimp_block block;
  wimp_event_no code;
  initialise();
  while(!quit) event_poll(&code, &block, NULL);
  exit(0);
}
00000000  23 69 6e 63 6c 75 64 65  20 3c 73 74 64 6c 69 62  |#include <stdlib|
00000010  2e 68 3e 0a 23 69 6e 63  6c 75 64 65 20 3c 73 74  |.h>.#include <st|
00000020  64 69 6f 2e 68 3e 0a 23  69 6e 63 6c 75 64 65 20  |dio.h>.#include |
00000030  3c 73 74 72 69 6e 67 2e  68 3e 0a 0a 23 69 6e 63  |<string.h>..#inc|
00000040  6c 75 64 65 20 22 4f 53  3a 74 6f 6f 6c 62 6f 78  |lude "OS:toolbox|
00000050  2e 68 22 0a 23 69 6e 63  6c 75 64 65 20 22 4f 53  |.h".#include "OS|
00000060  3a 6d 65 73 73 61 67 65  74 72 61 6e 73 2e 68 22  |:messagetrans.h"|
00000070  0a 23 69 6e 63 6c 75 64  65 20 22 4f 53 3a 77 69  |.#include "OS:wi|
00000080  6e 64 6f 77 2e 68 22 0a  23 69 6e 63 6c 75 64 65  |ndow.h".#include|
00000090  20 22 4f 53 3a 73 61 76  65 61 73 2e 68 22 0a 23  | "OS:saveas.h".#|
000000a0  69 6e 63 6c 75 64 65 20  22 4f 53 3a 6e 75 6d 62  |include "OS:numb|
000000b0  65 72 72 61 6e 67 65 2e  68 22 0a 23 69 6e 63 6c  |errange.h".#incl|
000000c0  75 64 65 20 22 4f 53 3a  77 72 69 74 61 62 6c 65  |ude "OS:writable|
000000d0  66 69 65 6c 64 2e 68 22  0a 23 69 6e 63 6c 75 64  |field.h".#includ|
000000e0  65 20 22 4f 53 3a 64 72  61 77 66 69 6c 65 2e 68  |e "OS:drawfile.h|
000000f0  22 0a 23 69 6e 63 6c 75  64 65 20 22 4f 53 3a 65  |".#include "OS:e|
00000100  76 65 6e 74 2e 68 22 0a  0a 23 69 6e 63 6c 75 64  |vent.h"..#includ|
00000110  65 20 22 65 76 65 6e 74  73 2e 68 22 0a 23 69 6e  |e "events.h".#in|
00000120  63 6c 75 64 65 20 22 73  70 69 72 6f 2e 68 22 0a  |clude "spiro.h".|
00000130  23 69 6e 63 6c 75 64 65  20 22 6d 61 69 6e 2e 68  |#include "main.h|
00000140  22 0a 0a 2f 2a 20 54 68  69 73 20 77 61 73 20 63  |"../* This was c|
00000150  6f 6d 70 69 6c 65 64 20  77 69 74 68 20 4f 53 4c  |ompiled with OSL|
00000160  69 62 20 72 65 6c 65 61  73 65 20 35 2e 31 2e 20  |ib release 5.1. |
00000170  54 6f 20 72 65 63 6f 6d  70 69 6c 65 20 79 6f 75  |To recompile you|
00000180  20 77 69 6c 6c 20 61 6c  73 6f 20 6e 65 65 64 0a  | will also need.|
00000190  20 20 20 74 68 65 20 65  76 65 6e 74 6c 69 62 20  |   the eventlib |
000001a0  68 65 61 64 65 72 20 28  68 2e 65 76 65 6e 74 29  |header (h.event)|
000001b0  20 66 72 6f 6d 20 74 68  65 20 4f 53 4c 69 62 20  | from the OSLib |
000001c0  65 78 61 6d 70 6c 65 73  20 64 69 72 65 63 74 6f  |examples directo|
000001d0  72 79 2e 0a 2a 2f 0a 0a  6d 65 73 73 61 67 65 74  |ry..*/..messaget|
000001e0  72 61 6e 73 5f 63 6f 6e  74 72 6f 6c 5f 62 6c 6f  |rans_control_blo|
000001f0  63 6b 20 6d 65 73 73 61  67 65 5f 62 6c 6f 63 6b  |ck message_block|
00000200  3b 0a 74 6f 6f 6c 62 6f  78 5f 62 6c 6f 63 6b 20  |;.toolbox_block |
00000210  20 09 09 65 76 65 6e 74  5f 69 64 5f 62 6c 6f 63  | ..event_id_bloc|
00000220  6b 3b 0a 69 6e 74 20 20  20 20 20 20 20 09 09 71  |k;.int       ..q|
00000230  75 69 74 20 3d 20 30 3b  0a 64 72 61 77 66 69 6c  |uit = 0;.drawfil|
00000240  65 5f 64 69 61 67 72 61  6d 20 09 2a 64 72 61 77  |e_diagram .*draw|
00000250  5f 66 69 6c 65 3b 0a 69  6e 74 20 09 09 09 64 72  |_file;.int ...dr|
00000260  61 77 5f 73 69 7a 65 2c  20 64 72 61 77 5f 6d 61  |aw_size, draw_ma|
00000270  78 3b 0a 6f 73 5f 74 72  66 6d 09 09 09 64 72 61  |x;.os_trfm...dra|
00000280  77 5f 74 72 66 6d 3b 0a  74 6f 6f 6c 62 6f 78 5f  |w_trfm;.toolbox_|
00000290  6f 09 09 73 61 76 65 61  73 5f 69 64 2c 64 69 73  |o..saveas_id,dis|
000002a0  70 6c 61 79 5f 69 64 3b  0a 0a 62 6f 6f 6c 20 72  |play_id;..bool r|
000002b0  65 64 72 61 77 5f 77 69  6e 64 6f 77 28 77 69 6d  |edraw_window(wim|
000002c0  70 5f 65 76 65 6e 74 5f  6e 6f 20 65 76 65 6e 74  |p_event_no event|
000002d0  5f 63 6f 64 65 2c 20 77  69 6d 70 5f 62 6c 6f 63  |_code, wimp_bloc|
000002e0  6b 20 2a 65 76 65 6e 74  2c 74 6f 6f 6c 62 6f 78  |k *event,toolbox|
000002f0  5f 62 6c 6f 63 6b 20 2a  69 64 5f 62 6c 6f 63 6b  |_block *id_block|
00000300  2c 76 6f 69 64 20 2a 68  61 6e 64 6c 65 29 0a 7b  |,void *handle).{|
00000310  0a 20 20 20 69 6e 74 20  68 65 69 67 68 74 3b 0a  |.   int height;.|
00000320  20 20 20 62 6f 6f 6c 20  6d 6f 72 65 3b 0a 20 20  |   bool more;.  |
00000330  20 77 69 6d 70 5f 77 69  6e 64 6f 77 5f 73 74 61  | wimp_window_sta|
00000340  74 65 20 73 74 61 74 65  3b 0a 20 20 20 77 69 6d  |te state;.   wim|
00000350  70 5f 64 72 61 77 20 62  6c 6f 63 6b 3b 0a 20 20  |p_draw block;.  |
00000360  20 6f 73 5f 62 6f 78 20  65 78 74 65 6e 74 3b 0a  | os_box extent;.|
00000370  0a 20 20 20 73 74 61 74  65 2e 77 20 3d 20 65 76  |.   state.w = ev|
00000380  65 6e 74 2d 3e 72 65 64  72 61 77 2e 77 3b 0a 20  |ent->redraw.w;. |
00000390  20 20 62 6c 6f 63 6b 2e  77 20 3d 20 65 76 65 6e  |  block.w = even|
000003a0  74 2d 3e 72 65 64 72 61  77 2e 77 3b 0a 20 20 20  |t->redraw.w;.   |
000003b0  77 69 6d 70 5f 67 65 74  5f 77 69 6e 64 6f 77 5f  |wimp_get_window_|
000003c0  73 74 61 74 65 28 26 73  74 61 74 65 29 3b 0a 20  |state(&state);. |
000003d0  20 20 77 69 6e 64 6f 77  5f 67 65 74 5f 65 78 74  |  window_get_ext|
000003e0  65 6e 74 28 30 2c 69 64  5f 62 6c 6f 63 6b 2d 3e  |ent(0,id_block->|
000003f0  74 68 69 73 5f 6f 62 6a  2c 26 65 78 74 65 6e 74  |this_obj,&extent|
00000400  29 3b 0a 20 20 20 68 65  69 67 68 74 20 3d 20 65  |);.   height = e|
00000410  78 74 65 6e 74 2e 79 31  20 2d 65 78 74 65 6e 74  |xtent.y1 -extent|
00000420  2e 79 30 3b 0a 20 20 20  64 72 61 77 5f 74 72 66  |.y0;.   draw_trf|
00000430  6d 2e 65 6e 74 72 69 65  73 5b 32 5d 5b 30 5d 20  |m.entries[2][0] |
00000440  3d 20 28 73 74 61 74 65  2e 76 69 73 69 62 6c 65  |= (state.visible|
00000450  2e 78 30 20 2d 20 73 74  61 74 65 2e 78 73 63 72  |.x0 - state.xscr|
00000460  6f 6c 6c 29 20 2a 32 35  36 3b 0a 20 20 20 64 72  |oll) *256;.   dr|
00000470  61 77 5f 74 72 66 6d 2e  65 6e 74 72 69 65 73 5b  |aw_trfm.entries[|
00000480  32 5d 5b 31 5d 20 3d 20  28 73 74 61 74 65 2e 76  |2][1] = (state.v|
00000490  69 73 69 62 6c 65 2e 79  31 20 2d 68 65 69 67 68  |isible.y1 -heigh|
000004a0  74 20 2d 73 74 61 74 65  2e 79 73 63 72 6f 6c 6c  |t -state.yscroll|
000004b0  29 20 2a 32 35 36 3b 0a  0a 20 20 20 6d 6f 72 65  |) *256;..   more|
000004c0  20 3d 20 77 69 6d 70 5f  72 65 64 72 61 77 5f 77  | = wimp_redraw_w|
000004d0  69 6e 64 6f 77 28 26 62  6c 6f 63 6b 29 3b 0a 20  |indow(&block);. |
000004e0  20 20 77 68 69 6c 65 20  28 6d 6f 72 65 29 0a 20  |  while (more). |
000004f0  20 20 7b 0a 20 20 20 20  20 20 77 69 6d 70 5f 73  |  {.      wimp_s|
00000500  65 74 5f 63 6f 6c 6f 75  72 28 31 32 38 29 3b 0a  |et_colour(128);.|
00000510  20 20 20 20 20 20 6f 73  5f 77 72 69 74 65 63 28  |      os_writec(|
00000520  6f 73 5f 56 44 55 5f 43  4c 47 29 3b 0a 20 20 20  |os_VDU_CLG);.   |
00000530  20 20 20 64 72 61 77 66  69 6c 65 5f 72 65 6e 64  |   drawfile_rend|
00000540  65 72 28 30 2c 20 64 72  61 77 5f 66 69 6c 65 2c  |er(0, draw_file,|
00000550  20 64 72 61 77 5f 73 69  7a 65 2c 20 26 64 72 61  | draw_size, &dra|
00000560  77 5f 74 72 66 6d 2c 0a  20 20 20 20 20 20 09 09  |w_trfm,.      ..|
00000570  20 20 20 20 20 20 26 28  62 6c 6f 63 6b 2e 62 6f  |      &(block.bo|
00000580  78 29 2c 20 30 29 3b 0a  20 20 20 20 20 20 6d 6f  |x), 0);.      mo|
00000590  72 65 20 3d 20 77 69 6d  70 5f 67 65 74 5f 72 65  |re = wimp_get_re|
000005a0  63 74 61 6e 67 6c 65 28  26 62 6c 6f 63 6b 29 3b  |ctangle(&block);|
000005b0  0a 20 20 20 7d 0a 0a 20  20 20 72 65 74 75 72 6e  |.   }..   return|
000005c0  20 31 3b 0a 7d 0a 0a 62  6f 6f 6c 20 75 70 64 61  | 1;.}..bool upda|
000005d0  74 65 5f 64 72 61 77 66  69 6c 65 28 62 69 74 73  |te_drawfile(bits|
000005e0  20 65 76 65 6e 74 5f 63  6f 64 65 2c 20 74 6f 6f  | event_code, too|
000005f0  6c 62 6f 78 5f 61 63 74  69 6f 6e 20 2a 65 76 65  |lbox_action *eve|
00000600  6e 74 2c 20 74 6f 6f 6c  62 6f 78 5f 62 6c 6f 63  |nt, toolbox_bloc|
00000610  6b 20 2a 69 64 5f 62 6c  6f 63 6b 2c 20 76 6f 69  |k *id_block, voi|
00000620  64 20 2a 68 61 6e 64 6c  65 29 0a 7b 0a 20 20 69  |d *handle).{.  i|
00000630  6e 74 20 6f 72 64 65 72  2c 73 63 61 6c 65 2c 61  |nt order,scale,a|
00000640  6e 67 6c 65 2c 69 2c 78  73 69 7a 65 2c 79 73 69  |ngle,i,xsize,ysi|
00000650  7a 65 3b 0a 20 20 64 6f  75 62 6c 65 20 78 73 63  |ze;.  double xsc|
00000660  61 6c 65 2c 79 73 63 61  6c 65 3b 0a 20 20 6f 73  |ale,yscale;.  os|
00000670  5f 62 6f 78 20 62 6f 78  3b 0a 20 20 63 68 61 72  |_box box;.  char|
00000680  20 74 75 72 6e 5b 36 35  5d 3b 0a 0a 20 20 6f 72  | turn[65];..  or|
00000690  64 65 72 20 3d 20 6e 75  6d 62 65 72 72 61 6e 67  |der = numberrang|
000006a0  65 5f 67 65 74 5f 76 61  6c 75 65 28 30 2c 69 64  |e_get_value(0,id|
000006b0  5f 62 6c 6f 63 6b 2d 3e  74 68 69 73 5f 6f 62 6a  |_block->this_obj|
000006c0  2c 34 29 3b 0a 20 20 69  66 20 28 6f 72 64 65 72  |,4);.  if (order|
000006d0  3e 36 34 29 20 6f 72 64  65 72 20 3d 20 36 34 3b  |>64) order = 64;|
000006e0  0a 20 20 69 66 20 28 6f  72 64 65 72 3c 31 29 20  |.  if (order<1) |
000006f0  6f 72 64 65 72 20 3d 20  31 3b 0a 20 20 6e 75 6d  |order = 1;.  num|
00000700  62 65 72 72 61 6e 67 65  5f 73 65 74 5f 76 61 6c  |berrange_set_val|
00000710  75 65 28 30 2c 69 64 5f  62 6c 6f 63 6b 2d 3e 74  |ue(0,id_block->t|
00000720  68 69 73 5f 6f 62 6a 2c  34 2c 6f 72 64 65 72 29  |his_obj,4,order)|
00000730  3b 0a 20 20 2f 2a 20 54  68 65 20 72 65 61 73 6f  |;.  /* The reaso|
00000740  6e 20 66 6f 72 20 61 6c  77 61 79 73 20 73 65 74  |n for always set|
00000750  74 69 6e 67 20 74 68 65  20 76 61 6c 75 65 2c 20  |ting the value, |
00000760  65 76 65 6e 20 69 66 20  74 68 65 20 6f 72 64 65  |even if the orde|
00000770  72 0a 20 20 20 20 20 73  65 65 6d 73 20 74 6f 20  |r.     seems to |
00000780  62 65 20 77 69 74 68 69  6e 20 74 68 65 20 62 6f  |be within the bo|
00000790  75 6e 64 73 2c 20 69 73  20 74 68 61 74 20 6e 75  |unds, is that nu|
000007a0  6d 62 65 72 72 61 6e 67  65 5f 67 65 74 5f 76 61  |mberrange_get_va|
000007b0  6c 75 65 20 73 6f 6d 65  74 69 6d 65 73 0a 20 20  |lue sometimes.  |
000007c0  20 20 20 72 65 74 75 72  6e 73 20 61 20 76 61 6c  |   returns a val|
000007d0  75 65 20 64 69 66 66 65  72 65 6e 74 20 74 6f 20  |ue different to |
000007e0  74 68 61 74 20 77 68 69  63 68 20 69 73 20 76 69  |that which is vi|
000007f0  73 69 62 6c 65 20 69 6e  20 74 68 65 20 69 63 6f  |sible in the ico|
00000800  6e 21 0a 20 20 20 20 20  54 68 69 73 20 6f 6e 6c  |n!.     This onl|
00000810  79 20 73 65 65 6d 73 20  74 6f 20 6f 63 63 75 72  |y seems to occur|
00000820  20 69 6e 20 77 72 69 74  61 62 6c 65 73 20 77 68  | in writables wh|
00000830  65 72 65 20 73 6f 6d 65  74 68 69 6e 67 20 6f 75  |ere something ou|
00000840  74 73 69 64 65 20 74 68  65 0a 20 20 20 20 20 62  |tside the.     b|
00000850  6f 75 6e 64 73 20 68 61  73 20 62 65 65 6e 20 74  |ounds has been t|
00000860  79 70 65 64 20 69 6e 2e  0a 20 20 2a 2f 0a 20 20  |yped in..  */.  |
00000870  73 63 61 6c 65 20 3d 20  6e 75 6d 62 65 72 72 61  |scale = numberra|
00000880  6e 67 65 5f 67 65 74 5f  76 61 6c 75 65 28 30 2c  |nge_get_value(0,|
00000890  69 64 5f 62 6c 6f 63 6b  2d 3e 74 68 69 73 5f 6f  |id_block->this_o|
000008a0  62 6a 2c 35 29 3b 0a 20  20 61 6e 67 6c 65 20 3d  |bj,5);.  angle =|
000008b0  20 6e 75 6d 62 65 72 72  61 6e 67 65 5f 67 65 74  | numberrange_get|
000008c0  5f 76 61 6c 75 65 28 30  2c 69 64 5f 62 6c 6f 63  |_value(0,id_bloc|
000008d0  6b 2d 3e 74 68 69 73 5f  6f 62 6a 2c 36 29 3b 0a  |k->this_obj,6);.|
000008e0  20 20 69 66 20 28 61 6e  67 6c 65 3e 31 37 39 29  |  if (angle>179)|
000008f0  20 61 6e 67 6c 65 20 3d  20 31 37 39 3b 0a 20 20  | angle = 179;.  |
00000900  69 66 20 28 61 6e 67 6c  65 3c 31 29 20 61 6e 67  |if (angle<1) ang|
00000910  6c 65 20 3d 20 31 3b 0a  20 20 6e 75 6d 62 65 72  |le = 1;.  number|
00000920  72 61 6e 67 65 5f 73 65  74 5f 76 61 6c 75 65 28  |range_set_value(|
00000930  30 2c 69 64 5f 62 6c 6f  63 6b 2d 3e 74 68 69 73  |0,id_block->this|
00000940  5f 6f 62 6a 2c 36 2c 61  6e 67 6c 65 29 3b 0a 20  |_obj,6,angle);. |
00000950  20 77 72 69 74 61 62 6c  65 66 69 65 6c 64 5f 67  | writablefield_g|
00000960  65 74 5f 76 61 6c 75 65  28 30 2c 69 64 5f 62 6c  |et_value(0,id_bl|
00000970  6f 63 6b 2d 3e 74 68 69  73 5f 6f 62 6a 2c 37 2c  |ock->this_obj,7,|
00000980  74 75 72 6e 2c 36 35 29  3b 0a 0a 20 20 66 6f 72  |turn,65);..  for|
00000990  28 69 3d 30 3b 69 3c 36  35 3b 69 2b 2b 29 20 7b  |(i=0;i<65;i++) {|
000009a0  0a 20 20 20 20 69 66 28  28 74 75 72 6e 5b 69 5d  |.    if((turn[i]|
000009b0  3d 3d 27 4c 27 29 7c 7c  28 74 75 72 6e 5b 69 5d  |=='L')||(turn[i]|
000009c0  3d 3d 27 6c 27 29 7c 7c  28 74 75 72 6e 5b 69 5d  |=='l')||(turn[i]|
000009d0  3d 3d 27 3c 27 29 29 20  74 75 72 6e 5b 69 5d 20  |=='<')) turn[i] |
000009e0  3d 20 31 3b 0a 20 20 20  20 65 6c 73 65 20 74 75  |= 1;.    else tu|
000009f0  72 6e 5b 69 5d 3d 30 3b  0a 20 20 7d 0a 0a 20 20  |rn[i]=0;.  }..  |
00000a00  64 72 61 77 5f 73 69 7a  65 20 3d 20 62 75 69 6c  |draw_size = buil|
00000a10  64 5f 64 72 61 77 5f 66  69 6c 65 28 6f 72 64 65  |d_draw_file(orde|
00000a20  72 2c 74 75 72 6e 2c 61  6e 67 6c 65 2c 73 63 61  |r,turn,angle,sca|
00000a30  6c 65 29 3b 0a 20 20 73  68 69 66 74 5f 64 72 61  |le);.  shift_dra|
00000a40  77 5f 66 69 6c 65 28 64  72 61 77 5f 66 69 6c 65  |w_file(draw_file|
00000a50  29 3b 0a 20 20 73 61 76  65 61 73 5f 73 65 74 5f  |);.  saveas_set_|
00000a60  64 61 74 61 5f 61 64 64  72 65 73 73 28 30 2c 73  |data_address(0,s|
00000a70  61 76 65 61 73 5f 69 64  2c 28 62 79 74 65 20 2a  |aveas_id,(byte *|
00000a80  29 64 72 61 77 5f 66 69  6c 65 2c 64 72 61 77 5f  |)draw_file,draw_|
00000a90  73 69 7a 65 2c 30 2c 30  29 3b 0a 20 20 73 61 76  |size,0,0);.  sav|
00000aa0  65 61 73 5f 73 65 74 5f  66 69 6c 65 5f 73 69 7a  |eas_set_file_siz|
00000ab0  65 28 30 2c 73 61 76 65  61 73 5f 69 64 2c 64 72  |e(0,saveas_id,dr|
00000ac0  61 77 5f 73 69 7a 65 29  3b 0a 0a 20 20 78 73 69  |aw_size);..  xsi|
00000ad0  7a 65 20 3d 20 64 72 61  77 5f 66 69 6c 65 2d 3e  |ze = draw_file->|
00000ae0  62 62 6f 78 2e 78 31 20  2d 20 64 72 61 77 5f 66  |bbox.x1 - draw_f|
00000af0  69 6c 65 2d 3e 62 62 6f  78 2e 78 30 3b 0a 20 20  |ile->bbox.x0;.  |
00000b00  79 73 69 7a 65 20 3d 20  64 72 61 77 5f 66 69 6c  |ysize = draw_fil|
00000b10  65 2d 3e 62 62 6f 78 2e  79 31 20 2d 20 64 72 61  |e->bbox.y1 - dra|
00000b20  77 5f 66 69 6c 65 2d 3e  62 62 6f 78 2e 79 30 3b  |w_file->bbox.y0;|
00000b30  0a 20 20 69 66 20 28 78  73 69 7a 65 3c 79 73 69  |.  if (xsize<ysi|
00000b40  7a 65 29 20 78 73 69 7a  65 20 3d 20 79 73 69 7a  |ze) xsize = ysiz|
00000b50  65 3b 0a 20 20 65 6c 73  65 20 79 73 69 7a 65 20  |e;.  else ysize |
00000b60  3d 20 78 73 69 7a 65 3b  0a 20 20 77 69 6e 64 6f  |= xsize;.  windo|
00000b70  77 5f 67 65 74 5f 65 78  74 65 6e 74 28 30 2c 64  |w_get_extent(0,d|
00000b80  69 73 70 6c 61 79 5f 69  64 2c 26 62 6f 78 29 3b  |isplay_id,&box);|
00000b90  0a 20 20 69 66 20 28 78  73 69 7a 65 21 3d 30 29  |.  if (xsize!=0)|
00000ba0  20 7b 0a 20 20 20 20 78  73 63 61 6c 65 20 3d 20  | {.    xscale = |
00000bb0  32 35 36 20 2a 20 28 62  6f 78 2e 78 31 29 3b 0a  |256 * (box.x1);.|
00000bc0  20 20 20 20 79 73 63 61  6c 65 20 3d 20 32 35 36  |    yscale = 256|
00000bd0  20 2a 20 28 61 62 73 28  62 6f 78 2e 79 30 29 29  | * (abs(box.y0))|
00000be0  3b 0a 20 20 20 20 78 73  63 61 6c 65 2f 3d 20 78  |;.    xscale/= x|
00000bf0  73 69 7a 65 3b 0a 20 20  20 20 79 73 63 61 6c 65  |size;.    yscale|
00000c00  2f 3d 20 79 73 69 7a 65  3b 0a 20 20 7d 0a 20 20  |/= ysize;.  }.  |
00000c10  65 6c 73 65 20 7b 0a 20  20 20 20 78 73 63 61 6c  |else {.    xscal|
00000c20  65 20 3d 20 31 3b 0a 20  20 20 20 79 73 63 61 6c  |e = 1;.    yscal|
00000c30  65 20 3d 20 31 3b 0a 20  20 7d 0a 20 20 64 72 61  |e = 1;.  }.  dra|
00000c40  77 5f 74 72 66 6d 2e 65  6e 74 72 69 65 73 5b 30  |w_trfm.entries[0|
00000c50  5d 5b 30 5d 20 3d 20 28  69 6e 74 29 20 28 31 3c  |][0] = (int) (1<|
00000c60  3c 31 36 29 20 2a 20 78  73 63 61 6c 65 3b 0a 20  |<16) * xscale;. |
00000c70  20 64 72 61 77 5f 74 72  66 6d 2e 65 6e 74 72 69  | draw_trfm.entri|
00000c80  65 73 5b 31 5d 5b 31 5d  20 3d 20 28 69 6e 74 29  |es[1][1] = (int)|
00000c90  20 28 31 3c 3c 31 36 29  20 2a 20 79 73 63 61 6c  | (1<<16) * yscal|
00000ca0  65 3b 0a 20 20 77 69 6e  64 6f 77 5f 66 6f 72 63  |e;.  window_forc|
00000cb0  65 5f 72 65 64 72 61 77  28 30 2c 64 69 73 70 6c  |e_redraw(0,displ|
00000cc0  61 79 5f 69 64 2c 26 62  6f 78 29 3b 0a 0a 20 20  |ay_id,&box);..  |
00000cd0  72 65 74 75 72 6e 20 31  3b 0a 7d 0a 0a 69 6e 74  |return 1;.}..int|
00000ce0  20 66 69 6e 61 6c 69 73  61 74 69 6f 6e 28 62 69  | finalisation(bi|
00000cf0  74 73 20 65 76 65 6e 74  5f 63 6f 64 65 2c 20 74  |ts event_code, t|
00000d00  6f 6f 6c 62 6f 78 5f 61  63 74 69 6f 6e 20 2a 65  |oolbox_action *e|
00000d10  76 65 6e 74 2c 20 74 6f  6f 6c 62 6f 78 5f 62 6c  |vent, toolbox_bl|
00000d20  6f 63 6b 20 2a 69 64 5f  62 6c 6f 63 6b 2c 20 76  |ock *id_block, v|
00000d30  6f 69 64 20 2a 68 61 6e  64 6c 65 29 0a 7b 0a 20  |oid *handle).{. |
00000d40  20 71 75 69 74 20 3d 20  31 3b 0a 20 20 72 65 74  | quit = 1;.  ret|
00000d50  75 72 6e 20 31 3b 0a 7d  0a 0a 69 6e 74 20 61 74  |urn 1;.}..int at|
00000d60  74 61 63 68 5f 68 61 6e  64 6c 65 72 73 28 62 69  |tach_handlers(bi|
00000d70  74 73 20 65 76 65 6e 74  5f 63 6f 64 65 2c 74 6f  |ts event_code,to|
00000d80  6f 6c 62 6f 78 5f 61 63  74 69 6f 6e 20 2a 65 76  |olbox_action *ev|
00000d90  65 6e 74 2c 74 6f 6f 6c  62 6f 78 5f 62 6c 6f 63  |ent,toolbox_bloc|
00000da0  6b 20 2a 69 64 5f 62 6c  6f 63 6b 2c 20 76 6f 69  |k *id_block, voi|
00000db0  64 20 2a 68 61 6e 64 6c  65 29 0a 7b 0a 20 20 69  |d *handle).{.  i|
00000dc0  66 20 28 21 73 74 72 63  6d 70 28 65 76 65 6e 74  |f (!strcmp(event|
00000dd0  2d 3e 64 61 74 61 2e 63  72 65 61 74 65 64 2e 6e  |->data.created.n|
00000de0  61 6d 65 2c 20 22 49 63  6f 6e 62 61 72 22 29 29  |ame, "Iconbar"))|
00000df0  20 7b 0a 20 20 20 20 65  76 65 6e 74 5f 72 65 67  | {.    event_reg|
00000e00  69 73 74 65 72 5f 74 6f  6f 6c 62 6f 78 5f 68 61  |ister_toolbox_ha|
00000e10  6e 64 6c 65 72 28 65 76  65 6e 74 5f 41 4e 59 2c  |ndler(event_ANY,|
00000e20  6d 65 6e 75 5f 71 75 69  74 5f 65 76 65 6e 74 2c  |menu_quit_event,|
00000e30  66 69 6e 61 6c 69 73 61  74 69 6f 6e 2c 30 29 3b  |finalisation,0);|
00000e40  0a 20 20 20 20 65 76 65  6e 74 5f 72 65 67 69 73  |.    event_regis|
00000e50  74 65 72 5f 74 6f 6f 6c  62 6f 78 5f 68 61 6e 64  |ter_toolbox_hand|
00000e60  6c 65 72 28 65 76 65 6e  74 5f 41 4e 59 2c 75 70  |ler(event_ANY,up|
00000e70  64 61 74 65 5f 64 72 61  77 66 69 6c 65 5f 65 76  |date_drawfile_ev|
00000e80  65 6e 74 2c 0a 20 20 20  20 09 09 09 09 20 20 20  |ent,.    ....   |
00000e90  75 70 64 61 74 65 5f 64  72 61 77 66 69 6c 65 2c  |update_drawfile,|
00000ea0  4e 55 4c 4c 29 3b 0a 20  20 20 20 65 76 65 6e 74  |NULL);.    event|
00000eb0  5f 72 65 67 69 73 74 65  72 5f 77 69 6d 70 5f 68  |_register_wimp_h|
00000ec0  61 6e 64 6c 65 72 28 65  76 65 6e 74 5f 41 4e 59  |andler(event_ANY|
00000ed0  2c 77 69 6d 70 5f 52 45  44 52 41 57 5f 57 49 4e  |,wimp_REDRAW_WIN|
00000ee0  44 4f 57 5f 52 45 51 55  45 53 54 2c 0a 20 20 20  |DOW_REQUEST,.   |
00000ef0  20 09 09 09 09 72 65 64  72 61 77 5f 77 69 6e 64  | ....redraw_wind|
00000f00  6f 77 2c 4e 55 4c 4c 29  3b 0a 20 20 7d 0a 20 20  |ow,NULL);.  }.  |
00000f10  69 66 20 28 21 73 74 72  63 6d 70 28 65 76 65 6e  |if (!strcmp(even|
00000f20  74 2d 3e 64 61 74 61 2e  63 72 65 61 74 65 64 2e  |t->data.created.|
00000f30  6e 61 6d 65 2c 22 53 61  76 65 41 73 22 29 29 0a  |name,"SaveAs")).|
00000f40  20 20 20 20 73 61 76 65  61 73 5f 69 64 20 3d 20  |    saveas_id = |
00000f50  69 64 5f 62 6c 6f 63 6b  2d 3e 74 68 69 73 5f 6f  |id_block->this_o|
00000f60  62 6a 3b 0a 20 20 69 66  20 28 21 73 74 72 63 6d  |bj;.  if (!strcm|
00000f70  70 28 65 76 65 6e 74 2d  3e 64 61 74 61 2e 63 72  |p(event->data.cr|
00000f80  65 61 74 65 64 2e 6e 61  6d 65 2c 22 44 69 73 70  |eated.name,"Disp|
00000f90  6c 61 79 22 29 29 0a 20  20 20 20 64 69 73 70 6c  |lay")).    displ|
00000fa0  61 79 5f 69 64 3d 69 64  5f 62 6c 6f 63 6b 2d 3e  |ay_id=id_block->|
00000fb0  74 68 69 73 5f 6f 62 6a  3b 0a 20 20 72 65 74 75  |this_obj;.  retu|
00000fc0  72 6e 20 31 3b 0a 7d 0a  0a 62 6f 6f 6c 20 6d 73  |rn 1;.}..bool ms|
00000fd0  67 71 75 69 74 5f 68 61  6e 64 6c 65 72 28 77 69  |gquit_handler(wi|
00000fe0  6d 70 5f 6d 65 73 73 61  67 65 20 2a 6d 65 73 73  |mp_message *mess|
00000ff0  61 67 65 2c 20 76 6f 69  64 20 2a 68 61 6e 64 6c  |age, void *handl|
00001000  65 29 0a 7b 0a 20 20 71  75 69 74 20 3d 20 31 3b  |e).{.  quit = 1;|
00001010  0a 20 20 72 65 74 75 72  6e 20 31 3b 0a 7d 0a 0a  |.  return 1;.}..|
00001020  76 6f 69 64 20 69 6e 69  74 69 61 6c 69 73 65 28  |void initialise(|
00001030  76 6f 69 64 29 0a 7b 0a  20 20 77 69 6d 70 5f 70  |void).{.  wimp_p|
00001040  6f 6c 6c 5f 66 6c 61 67  73 20 6d 61 73 6b 3b 0a  |oll_flags mask;.|
00001050  0a 20 20 65 76 65 6e 74  5f 69 6e 69 74 69 61 6c  |.  event_initial|
00001060  69 73 65 28 26 65 76 65  6e 74 5f 69 64 5f 62 6c  |ise(&event_id_bl|
00001070  6f 63 6b 29 3b 0a 20 20  6d 61 73 6b 20 3d 20 77  |ock);.  mask = w|
00001080  69 6d 70 5f 4d 41 53 4b  5f 4e 55 4c 4c 3b 0a 20  |imp_MASK_NULL;. |
00001090  20 65 76 65 6e 74 5f 73  65 74 5f 6d 61 73 6b 28  | event_set_mask(|
000010a0  6d 61 73 6b 29 3b 0a 0a  20 20 65 76 65 6e 74 5f  |mask);..  event_|
000010b0  72 65 67 69 73 74 65 72  5f 74 6f 6f 6c 62 6f 78  |register_toolbox|
000010c0  5f 68 61 6e 64 6c 65 72  28 65 76 65 6e 74 5f 41  |_handler(event_A|
000010d0  4e 59 2c 20 61 63 74 69  6f 6e 5f 4f 42 4a 45 43  |NY, action_OBJEC|
000010e0  54 5f 41 55 54 4f 5f 43  52 45 41 54 45 44 2c 0a  |T_AUTO_CREATED,.|
000010f0  20 20 09 09 09 09 20 61  74 74 61 63 68 5f 68 61  |  .... attach_ha|
00001100  6e 64 6c 65 72 73 2c 4e  55 4c 4c 29 3b 0a 20 20  |ndlers,NULL);.  |
00001110  65 76 65 6e 74 5f 72 65  67 69 73 74 65 72 5f 6d  |event_register_m|
00001120  65 73 73 61 67 65 5f 68  61 6e 64 6c 65 72 28 6d  |essage_handler(m|
00001130  65 73 73 61 67 65 5f 51  55 49 54 2c 20 6d 73 67  |essage_QUIT, msg|
00001140  71 75 69 74 5f 68 61 6e  64 6c 65 72 2c 20 4e 55  |quit_handler, NU|
00001150  4c 4c 29 3b 0a 0a 20 20  74 6f 6f 6c 62 6f 78 5f  |LL);..  toolbox_|
00001160  69 6e 69 74 69 61 6c 69  73 65 28 30 2c 33 31 30  |initialise(0,310|
00001170  2c 20 28 77 69 6d 70 5f  6d 65 73 73 61 67 65 5f  |, (wimp_message_|
00001180  6c 69 73 74 20 2a 29 77  69 6d 70 5f 6d 65 73 73  |list *)wimp_mess|
00001190  61 67 65 73 2c 0a 20 20  28 74 6f 6f 6c 62 6f 78  |ages,.  (toolbox|
000011a0  5f 61 63 74 69 6f 6e 5f  6c 69 73 74 20 2a 29 74  |_action_list *)t|
000011b0  6f 6f 6c 62 6f 78 5f 65  76 65 6e 74 73 2c 20 22  |oolbox_events, "|
000011c0  3c 53 70 69 72 6f 4c 61  74 24 44 69 72 3e 22 2c  |<SpiroLat$Dir>",|
000011d0  20 26 6d 65 73 73 61 67  65 5f 62 6c 6f 63 6b 2c  | &message_block,|
000011e0  0a 20 20 26 65 76 65 6e  74 5f 69 64 5f 62 6c 6f  |.  &event_id_blo|
000011f0  63 6b 2c 20 30 2c 20 30  29 3b 0a 0a 20 20 64 72  |ck, 0, 0);..  dr|
00001200  61 77 5f 6d 61 78 20 20  3d 20 49 4e 49 54 49 41  |aw_max  = INITIA|
00001210  4c 5f 53 49 5a 45 3b 0a  20 20 64 72 61 77 5f 66  |L_SIZE;.  draw_f|
00001220  69 6c 65 20 3d 20 6d 61  6c 6c 6f 63 28 64 72 61  |ile = malloc(dra|
00001230  77 5f 6d 61 78 29 3b 0a  20 20 64 72 61 77 5f 73  |w_max);.  draw_s|
00001240  69 7a 65 20 3d 20 69 6e  69 74 5f 64 72 61 77 5f  |ize = init_draw_|
00001250  66 69 6c 65 28 64 72 61  77 5f 66 69 6c 65 29 3b  |file(draw_file);|
00001260  0a 7d 0a 0a 69 6e 74 20  6d 61 69 6e 28 69 6e 74  |.}..int main(int|
00001270  20 61 72 67 63 2c 20 63  68 61 72 20 2a 61 72 67  | argc, char *arg|
00001280  76 5b 5d 29 0a 7b 0a 20  20 77 69 6d 70 5f 62 6c  |v[]).{.  wimp_bl|
00001290  6f 63 6b 20 62 6c 6f 63  6b 3b 0a 20 20 77 69 6d  |ock block;.  wim|
000012a0  70 5f 65 76 65 6e 74 5f  6e 6f 20 63 6f 64 65 3b  |p_event_no code;|
000012b0  0a 20 20 69 6e 69 74 69  61 6c 69 73 65 28 29 3b  |.  initialise();|
000012c0  0a 20 20 77 68 69 6c 65  28 21 71 75 69 74 29 20  |.  while(!quit) |
000012d0  65 76 65 6e 74 5f 70 6f  6c 6c 28 26 63 6f 64 65  |event_poll(&code|
000012e0  2c 20 26 62 6c 6f 63 6b  2c 20 4e 55 4c 4c 29 3b  |, &block, NULL);|
000012f0  0a 20 20 65 78 69 74 28  30 29 3b 0a 7d 0a        |.  exit(0);.}.|
000012fe