home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_23_1988_Transactor_Publishing.d64 / automata.src < prev    next >
Text File  |  2023-02-26  |  5KB  |  291 lines

  1. ;  *******************
  2. ;  **               **
  3. ;  **   cellular    **
  4. ;  **   automata    **
  5. ;  **               **
  6. ;  *******************
  7. ;
  8. ;
  9. ;
  10. ;  geometric  computer
  11. ;        artforms
  12. ;
  13. ;        for  the
  14. ;  commodore  64 & 128
  15. ;
  16. ;     by  ian  adam
  17. ;     vancouver  bc
  18. ;
  19. ;     march    1987
  20. ;
  21. ;
  22. ; the screen image is plotted 1
  23. ; line at a time.  each pixel
  24. ; depends on the sum of the 3
  25. ; pixels above, using a preset
  26. ; code supplied by the user.
  27. ;
  28.  zp     = $a6 ;8 bytes temporary
  29.  rows   = $a6
  30.  column = $a7
  31.  bits   = $a8
  32.  aval   = $a9
  33.  bval   = $aa
  34.  adread = $fa ;read address
  35.  adwrit = $fc ;write address
  36.  output = $fe
  37.  screen = $2000
  38.  bsout  = $ffd2
  39.  ;
  40.  *=$1700 ;same for both
  41.  ;
  42.  codes *=*+10 ;these are the rules
  43.  ; for plotting pixels (10 bytes)
  44.  ;
  45.  ; *************************
  46.  ; **                     **
  47.  ; ** start plotting here **
  48.  ; **                     **
  49.  ; *************************
  50. ;
  51. *=$170c ;friendly address (5900)
  52. ;
  53. ; set up pointers
  54. ;
  55.  ldy #>screen ;set addresses
  56.  sty adread+1
  57.  sty adwrit+1
  58.  ldy #$01
  59.  sty adwrit ;write to $2001
  60.  dey
  61.  sty adread ;read $2000
  62.  ;
  63.  ldx #$c7
  64.  stx rows ;199 rows to do
  65. ;
  66. ; setup for each row
  67. ;
  68. startr ldx #$27 ;40 bytes per line
  69.  stx column
  70.  ;
  71.  ; aval is pixel above & left
  72.  ; bval represents pixel above
  73.  ; cval is pixel above & right
  74.  ;
  75.  sty aval ;aval = 0 to start row
  76. ;
  77. ; prepare one byte at a time
  78. ;
  79. startc lda (adread),y ;get byte above
  80.  sta bits
  81.  ;
  82.  lda column
  83.  beq get1st
  84.  ;note: we need the first pixel
  85.  ;from the next byte to the right,
  86.  ;to be cval for the 4th pixel of
  87.  ;this byte. on the last screen
  88.  ;block of a row, counter 'column'
  89.  ;will be zero.  in this case,
  90.  ;a 0 will be put into variable
  91.  ;cval for the last pixel in the
  92.  ;row. if not the last block, then
  93.  ;get a pixel from the next block:
  94.  ;
  95.  ldy #8
  96.  lda (adread),y
  97.  ;
  98. get1st asl a
  99.  rol bits ;extra pixel into bits
  100.  rol a
  101.  rol bits
  102.  rol a ;and 1st pixel rolls
  103.  and #3 ;into a, then
  104.  sta bval ;...into bval
  105. ;
  106. ; pixel loop for one byte
  107. ;
  108.  ldy #4 ;4 pixels
  109. pxloop lda #0
  110.  rol bits ;get one pixel
  111.  rol a
  112.  rol bits
  113.  rol a
  114.  pha ;this pixel is cval
  115.  ;
  116.  adc bval ;form sum of 3 pixels
  117.  adc aval ;(carry is clear)
  118.  tax
  119.  ;
  120.  lda bval ;shift records over
  121.  sta aval
  122.  pla ;get cval back
  123.  sta bval
  124.  ;
  125.  lda codes,x ;get new colour value
  126.  asl output ;make room in byte, &
  127.  asl output
  128.  ora output ;put pixel in stream
  129.  sta output
  130.  ;
  131.  dey ;move to next pixel
  132.  bne pxloop
  133.  ;
  134.  ; finished pixel loop for
  135.  ; byte, so output the result:
  136.  ;
  137.  sta (adwrit),y
  138.  ;
  139.  ; update addresses:
  140.  ;
  141.  clc
  142.  dec column ;where on screen?
  143.  bpl oldrow
  144. ;
  145. ; here because end of row, so
  146. ;
  147. ; update pointers to start next row
  148. ;
  149.  ldx #2 ;do adwrit first
  150. newrw1 lda adread,x
  151.  and #7
  152.  cmp #7 ;check if bottom of block
  153.  beq newlin
  154.  ;
  155.  sec ;next pixel row, subtract 311
  156.  lda adread,x
  157.  sbc #$37
  158.  sta adread,x
  159.  lda adread+1,x
  160.  sbc #1
  161.  sta adread+1,x
  162.  bne newrw2
  163.  ;
  164. newlin inc adread,x ;if bottom of
  165.  bne newrw2 ;block, just add 1
  166.  inc adread+1,x
  167.  ;
  168. newrw2 dex ;now do adread
  169.  dex
  170.  beq newrw1
  171.  ;
  172.  dec rows ;ready for next row
  173.  bne startr
  174.  rts
  175. ;
  176. ; here because in middle of row
  177. ;
  178. ; so move to next byte
  179. ;
  180. oldrow ldx #2 ;start with adwrit
  181.  ;
  182. oldrw2 lda adread,x ;mid column so
  183.  adc #8 ;move over one byte
  184.  sta adread,x
  185.  bcc oldrw3
  186.  inc adread+1,x
  187.  clc
  188.  ;
  189. oldrw3 dex
  190.  dex
  191.  beq oldrw2 ;now do adread
  192.  jmp startc ;start next column
  193. ;
  194.  ;
  195.  ; **********************
  196.  ; **                  **
  197.  ; ** screen dump here **
  198.  ; **                  **
  199.  ; **********************
  200. ;
  201. rowout = adwrit
  202. colout = adwrit+1
  203. ;
  204. messag .byt 27,65,8,13,10,27,75,64,1
  205. ;
  206. ; 27,65,8 sets graphics linefeed
  207. ; 13,10   is carriage return & lf
  208. ; 27,75,64,1 for 320 graphics bytes
  209. ; change these for other printers
  210. ;
  211. ;
  212. ; printer is already accessed as
  213. ; CMD file by BASIC program
  214. ;
  215. ;
  216. * = $17ac ;6060 is a friendly start
  217. ;
  218. ; set up pointer
  219. ;
  220.  ldy #>screen ;set screen address
  221.  sty adread+1
  222.  ldy #$00
  223.  sty adread
  224.  ldy #$19
  225.  sty rowout ;25 rows to do
  226. ;
  227. ; set up for row of 320 bytes
  228. ;
  229. oprow ldy #0
  230. linmsg lda messag,y
  231.  jsr bsout
  232.  iny
  233.  cpy #9
  234.  bne linmsg
  235.  ;
  236.  ldy #$28 ;output 40 columns
  237.  sty colout
  238.  ;
  239. block ldy #7 ;one block of 8 bytes
  240. bytelp lda (adread),y
  241.  ;
  242.  ; reorient bytes 90 degrees
  243.  ;
  244.  ; screen bytes are horizontal
  245.  ; printer bytes are vertical
  246.  ;
  247.  ldx #7
  248. rotate rol a ;one bit into each
  249.  ror zp,x ; of 8 bytes
  250.  ;change ror to rol if your
  251.  ;printer does graphics inverted
  252.  ;
  253.  dex
  254.  bpl rotate
  255.  ;
  256.  dey
  257.  bpl bytelp
  258. ;
  259. ; move pointer 8 bytes
  260. ; for next screen block
  261. ;
  262.  lda #7
  263.  tax
  264.  sec
  265.  adc adread
  266.  sta adread
  267.  bcc oploop
  268.  inc adread+1
  269. ;
  270. ; output 8 bytes
  271. ;
  272. oploop lda zp,x
  273.  jsr bsout
  274.  dex
  275.  bpl oploop
  276. ;
  277. ; update counters
  278. ;
  279.  dec colout ;next column
  280.  bne block
  281.  ;
  282.  dec rowout ;next row
  283.  bne oprow
  284.  ;
  285.  rts
  286.  ;
  287.  ; BASIC takes care of unlistening
  288.  ; and closing printer file.
  289.  ;
  290. .end
  291.