$ > M7Plot/src - MODE 7 plotting  12-Apr-1994 J.G.Harston 0 Implements DRAW/MOVE &00-&0F, PLOT &40-&47 (( Also PLOT &80+n to CLG to colour n 2 Syntax: *M7PLOT (ON|OFF) <: F*OSWRCH=&FFEE:OSNEWL=&FFE7:OSBYTE=&FFF4 POSARGS=&FFDA:lptr=&A8 Zvduv=&0226 dscrMap=&0356 n$originXY=&030C: external coords x$latestXY=&0310: external coords $beforeXY=&0314: external coords plotCM=&031F .vduQXY=&0320:vduQX=vduQXY+0:vduQY=vduQXY+2 @plotXY=&0324:plotX=plotXY+0:plotY=plotXY+2: internal coords @lastXY=&0328:lastX=lastXY+0:lastY=lastXY+2: internal coords @prevXY=&032C:prevX=prevXY+0:prevY=prevXY+2: internal coords pixelY=&00D1 @cordXY=&00D2:x1=cordXY+0:y1=cordXY+1:x2=cordXY+2:y2=cordXY+3 .charXY=&00D6:charX=charXY+0:charY=charXY+1 .oldXY =&00DA:oldX =oldXY +0:oldY =oldXY +1 :dx=&DC:dy=&DD:xi=&DE:yi=&DF:ai=dx:bi=dy:d=&330:d=charX :  &D0 = VDUSTAT  &D1 = pixelY pixel line  &D2 = x1  &D3 = y1 " &D4 = x2 , &D5 = y2 6 &D6/7 = charX, charY @$ &D8/9 = character address base J &DA/B = oldX, oldY T &DC/D = dx, dy, ai, bi ^ &DE/F = xi, yi h: r mcode% 600:load%=&FFFF08CA | P=0 1 O%=mcode%:P%=load% [OPT P*3+4  .init% >LDA #1:LDX #lptr:LDY #0:JSR OSARGS :\ ptr=>command line BLDA (lptr),Y:CMP #13:BEQ switchOn :\ M7PLOT -> turn on  LDX #&FF  .switchLp 9INX:LDA &FF00,X:CMP #&60:BNE switchLp :\ Look for RTS @INY:LDA (lptr),Y: #&DF :\ M7PLOT ON -> turn on ALDY #&FF:CMP #"N":BNE switchOff :\ M7PLOT OFF -> turn off  .switchOn )LDX #newplot 255:LDY #newplot 256 .switchOff STX vduv+0:STY vduv+1 :  .plotquit &RTS 0 .newplot :BCS plotquit :\ VDU 23,nn D!\ &031F = number, also in A N\ &0320 = X X'\ &0322 = Y after cycling: b!\ &0324 = last X (int) plotX l!\ &0326 = last Y (int) plotY v!\ &0328 = prev X (int) lastX !\ &0328 = prev Y (int) lastY !\ &032C = temp X (int) prevX !\ &032E = temp Y (int) prevY \ %\ Start by converting coordinates BLDY scrMap:CPY #4:BNE plotquit:PHA :\ Not map 4, teletext mode B #4: #4:TAY:JSR plotadd :\ Add origin or previous point : \ Cycle the coordinates  LDX #3  .loop <\LDA latestXY,X:\STA beforeXY,X :\ Only needed for fills 4\LDA lastXY,X:\STA prevXY,X :\ These are the 5LDA plotXY,X:STA lastXY,X :\ three plotting  2LDA vduQXY,X:STA plotXY,X :\ coordinates STA latestXY,X  DEX:BPL loop *: 4\ Scale the coordinates >.plotscale H.LDX #plotX-&300 :\ 1280 R9LDY #4:JSR plotdiv:PHP :\ DIV 16 => 80, save sign \ LDA plotX fCMP #60:BCC P%+4:SBC #1 p.CMP #20:BCC P%+4:SBC #1 :\ Adjust => 78 z3PLP:BPL P%+4:ADC #2 :\ Adjust if negative STA plotX:PHA : .LDX #plotY-&300 :\ 1024 9LDY #3:JSR plotdiv:PHP :\ DIV 8 => 125, save sign LDA plotY:STA pixelY LSR A:ADC #13:ADC pixelY ROR A:LSR A:LSR A ADC pixelY:ROR A:ADC pixelY .ROR A:LSR A:LSR A :\ DIV 5 => 25 .CLC:ADC plotY :\ 25+125 => 150 .ROR A :\ DIV 2 => 75 3PLP:BPL P%+4:ADC #&66 :\ Adjust if negative  STA plotY : STA y1:STA y2 8PLA:STA x1:STA x2 :\ Point to start plotting $0PLA:TAY :\ Get PLOT action .8 #&F8:CMP #&80:BEQ clg :\ PLOT &8x -> set up screen 81TYA:CMP #&48:BCS plotexit :\ Not DRAW or PLOT B1 #3:BEQ plotexit :\ %xxxxxxxx00 - MOVE LLDA #134:JSR OSBYTE V6STX oldX:STY oldY :\ Save current text X,Y `3LDA &D0:PHA:A #2:STA &D0:\ Don't scroll screen jLDA plotCM:JSR plotaction t7PLA:STA &D0:BCS plotexit :\ Skip past if no output ~1LDA #31:JSR OSWRCH :\ Restore text X,Y LDA oldX:JSR OSWRCH LDA oldY:JMP OSWRCH  .plotexit RTS : .clg LDA #22:JSR OSWRCH )LDA #&87:JSR OSWRCH :\ MODE &87 4LDX #25:BNE initgo :\ Initialise 25 lines  .initlp JSR OSNEWL  .initgo .TYA: #&10:JSR OSWRCH :\ Set colour code  DEX:BNE initlp LDA #30:JMP OSWRCH : (.plotaction 23CMP #&40:BCC plotdraw :\ %00xxxxxx - DRAW <3: :\ %0100xxxx - PLOT F8: :\ %xxxxxx01 - set pixel P;: :\ %xxxxxx10 - invert pixel Z:: :\ %xxxxxx11 - unset pixel d&\ Core plot code, x1=hardware 0-77 n&\ y1=hardware 0-74 x.plotpoint -LDA y1:CMP #75:BCS plotnull :\ Off screen (LSR A:ADC #21:LSR A:LDY #3 :\ DIV 3  .plotdiv3 ADC y1:ROR A:LSR A 0DEY:BNE plotdiv3:STA charY :\ DIV 3 => 25 .ASL A:ADC charY :\ 3*(Y DIV 3) 2SBC y1:STA pixelY :\ 3*(Y DIV 3) - Y -LDA x1:CMP #78:BCS plotnull :\ Off screen PHA : 2LDA #31:JSR OSWRCH :\ Position cursor 'PLA:LSR A:PHP:CLC:ADC #1:JSR OSWRCH $LDA #24:SEC:SBC charY:JSR OSWRCH 0LDA #135:JSR OSBYTE :\ Get character PLP:LDA pixelY:ROL A:TAY >LDA plotCM:LSR A:BCS plotpix:\ %xxxxxxx1 - set/unset pixel ";TXA:BCC plotinv :\ %xxxxxx10 - invert pixel , .plotpix 68LSR A:TXA :\ %xxxxxx01 - set pixel @:.plotset :\ %xxxxxx11 - unset pixel J$A plotchars-&FA,Y:BCC plotwrite T .plotinv ^ plotchars-&FA,Y h.plotwrite r2A #&80:JSR OSWRCH:CLC :\ Output character | .plotnull RTS : :\ Draw from lastX,lastY to plotX,plotY hardware coords  .plotdraw 4PHA :\ Save plot command 2LDA lastX:STA x1 :\ lastXY is start LDA lastY:STA y1 : +\ Draw a line using Bresenham algorithm '\ Draw from x1,y1 to x2,y2 \ '\ Decide direction to draw and step  LDX #1 .drawSignLp +LDA x1,X:CMP #&A8:LDA x2,X:BCC drawPlus &CMP #&A8:BCS drawSame:BCC drawDiff & .drawPlus 0CMP #&A8:BCC drawSame : .drawDiff D"LDA x2,X:CMP x1,X:JMP drawSign N .drawSame XLDA x1,X:CMP x2,X b .drawSign l7BCS drawSub :\ x1x2 y1 x2 *3TXA:PHA:JSR plotpoint :\ plot(x1,y1) 4PLA:TAX: #1:TAY >5LDA d:CLC:BMI drawXYb :\ diff<0, inc b H5.drawXYa :\ diff>0, inc a R0LDA xi,Y:ADC x1,Y:sta x1,Y :\ y1 += yi \LDA ai:CLC:BCC drawXYplot f .drawXYb p2LDA bi :\ diff += bi z.drawXYplot 3ADC d:sta d :\ update diff 0LDA xi,X:CLC:ADC x1,X:sta x1,X :\ x1 += xi  .drawXYgo ;LDA x1,X: x2,X:BNE drawXYlp :\ Loop until last point 6PLA: #8:BNE drawdone :\ Omit final point JMP plotpoint :  .plotdiv LDA &301,X:ASL A ROR &301,X:ROR &300,X DEY:BNE plotdiv 'LDA &301,X:\ Return with flags=sign  .drawdone  CLC:RTS :  .plotadd $!LDX #vduQXY-&300:JSR plotadd2 .INX:INX:INY:INY 8 .plotadd2 BCLC L*LDA &300,X:ADC originXY+0,Y:STA &300,X V*LDA &301,X:ADC originXY+1,Y:STA &301,X `RTS j: t.plotchars ~EQUB &01:EQUB &02:EQUB &04 EQUB &08:EQUB &10:EQUB &40 : ']: P%>&FFFF0B00:"Code overflow":  D"*SAVE M7PLOT ";~mcode%;" ";~O%;" ";~init%&FFFF0000;" ";~load%  test1 &87,0,0  Y%=0 999 8  69,16+0000,Y%  69,16+1229,Y% ! 69,16+Y%*12301000,000+Y%+0 ! 69,16+Y%*12301000,999-Y%+1  69,16+Y%*12301000,000  69,16+Y%*12301000,999 : (''' 2 < test2 F &87,0,0 PX%=0:Y%=890:V%=0:W%=0 Z d V%,W%: X%,Y% n5,23);135;X%;",";Y%; x&" ";?dx;" ";?dy;" ";?xi;" ";?yi; "" ";?ai;" ";?bi;" ";?d;" "; 5,24);135;?&8F;" "; A%=:13  V%,W%: 7,X%,Y% # A%="."A%=">":X%=X%+1-9*-1 # A%=","A%="<":X%=X%-1+9*-1 # A%="A"A%="a":Y%=Y%+1-9*-1 # A%="Z"A%="z":Y%=Y%-1+9*-1 # A%="H"A%="h":V%=V%+1-4*-1 # A%="G"A%="g":V%=V%-1+4*-1 # A%="Y"A%="y":W%=W%+1-4*-1 # A%="B"A%="b":W%=W%-1+4*-1    test3  &87,0,0 "% 0,0: 1279,0: 1279,999: 0,999 , 0,0: 640,500: 1279,999 6 0,999: 640,500: 1279,0 @! 440,400: 1,420,0: 1,0,199 J 1,-420,0: 1,0,-199 T# 440,100: 10,420,0: 10,0,199 ^ 10,-420,0: 10,0,-199 h r''' | test4 &87,0,0 % 0,0: 1279,0: 1279,999: 0,999  0,0: 1279,999  0,999: 1279,0  '''  test5 &87,0,0 1 16+0,0: 16+1229,0: 16+1229,999: 16+0,999  16+0,0: 16+1229,999  16+0,999: 16+1229,0  '''