* Copper Monitor (C) 1988 by Stefan Kemeny *

ExecBase        =        4
GetMsg          = -30 -342
OldOpenLibrary  = -30 -378
CloseLibrary    = -30 -384
CloseWindow     = -30 - 42
EndRequest      = -30 - 90
OpenWindow      = -30 -174
RefreshGadgets  = -30 -192
Request         = -30 -210
Text            = -30 - 30
SetAPen         = -30 -312
SetBPen         = -30 -318
Move            = -30 -210
SPFix           = -30 -  0
SPFlt           = -30 -  6
SPSub           = -30 - 42
SPMul           = -30 - 48
SPDiv           = -30 - 54

Start:
 bsr.L OeffneLibraries
 bsr.L InitFenster
 bsr.L GadgetsRefresh
HauptSchleife:
 bsr.L InitAusgabe
 bsr.L ListCopper
 bsr.L GetIDCMP
 tst.l d0
beq.S HauptSchleife
 move.l d0,a0
 move.l 20(a0),d0
 cmpi.l #$200,d0
beq.S Ende1
 cmpi.l #8,d0
 bne.S NamensToggle
 move.w 24(a0),d0
 cmpi.w #$0068,d0
bne.S HauptSchleife
 clr.l d0
 move.w 34(a0),d0
 subi.w #10,d0
 divu #9,d0
 andi.l #$ffff,d0
 cmpi.b #15,d0
bhi.S HauptSchleife
 add.l SchieberAktuell,d0
 mulu #4,d0
 move.l CListStart,a0
 add.l d0,a0
 move.l a0,EditierteAdresse
 bsr.S EditiereCopper
bra.S HauptSchleife
NamensToggle:
 move.l 28(a0),d0
 cmpi.l #BoolGadget1,d0
bne.S HauptSchleife
 move.l NamenFlag,d0
 bchg #0,d0
 move.l d0,NamenFlag
bra.L HauptSchleife
Ende1:
 bsr.L SchliesseWindow
Ende2:
 bsr.L SchliesseLibraries
rts

EditiereCopper:
 move.l CListStart,d0
 move.l #$100000,d1
 move.l #16,d2
 move.l #1,d3
 lea In2Data,a0
 bsr.L ConvertAlles
 move.l CListEnde,d0
 move.l #$100000,d1
 move.l #16,d2
 move.l #1,d3
 lea In3Data,a0
 bsr.L ConvertAlles
 move.l CListLaenge,d0
 move.l #1000,d1
 move.l #10,d2
 move.l #2,d3
 lea In4Data,a0
 bsr.L ConvertAlles
 move.l EditierteAdresse,a0
 clr.l d0
 move.w (a0)+,d0
 move.l #$1000,d1
 move.l #16,d2
 move.l #1,d3
 move.l a0,-(sp)
 lea St1Puff,a0
 bsr.L ConvertAlles
 move.l St1Puff,Un1Puff
 move.l (sp)+,a0
 move.w (a0)+,d0
 move.l #$1000,d1
 move.l #16,d2
 move.l #1,d3
 lea St2Puff,a0
 bsr.L ConvertAlles
 move.l St2Puff,Un2Puff
 move.l IntBase,a6
 lea.l EditRequester1,a0
 move.l Window,a1
 jsr Request(a6)
OKPress:
 bsr.L GetIDCMP
 tst.l d0
beq.S OKPress
 move.l d0,a0
 move.l 20(a0),d0
 cmpi.w #$20,d0
bne.S OKPress
 move.l 28(a0),d0
 cmpi.l #BoolGadget2,d0
bne.S OKPress
RequesterEnde:
 lea.l St1Puff,a0
 bsr.S PruefeHex
 cmpi.l #$f0000000,d0
beq.S OKPress
 move.l d0,d7
 lea.l St2Puff,a0
 bsr.S PruefeHex
 cmpi.l #$f0000000,d0
beq.S OKPress
 move.l d0,d1
 move.l d7,d0
 lsl.l #8,d0
 lsl.l #8,d0
 add.l d1,d0
 move.l EditierteAdresse,a0
 move.l d0,(a0)
 move.l IntBase,a6
 lea.l EditRequester1,a0
 move.l Window,a1
 jsr EndRequest(a6)
rts

PruefeHex:
 move.l (a0),d0
 move.l #3,d1
PruefeRoll1:
 cmpi.b #32,d0
 bne.S PruefeRoll3
 clr.b d0
PruefeRoll3:
 tst.b d0
 bne.S PruefeRoll2
 lsr.l #8,d0
 addi.l #$30000000,d0
PruefeRoll2:
 dbra d1,PruefeRoll1
 move.l d0,(a0)
 move.l a0,-(sp)
 move.l #3,d0
PruefeKlein1:
 move.b (a0),d1
 cmpi.b #64,d1
 bls.S PruefeKlein2
 cmpi.b #70,d1
 bhi.S PruefeKlein2
 addi.b #32,d1
PruefeKlein2:
 move.b d1,(a0)+
dbra d0,PruefeKlein1
 move.l (sp)+,a0
 move.l a0,-(sp)
 move.l #3,d0
PruefeErlaubt:
 move.b (a0)+,d1
 cmpi.b #47,d1
 bls.S PruefeFehler
 cmpi.b #102,d1
 bhi.S PruefeFehler
 cmpi.b #57,d1
 bls.S PruefeGueltig
 cmpi.b #96,d1
 bls.S PruefeFehler
PruefeGueltig:
dbra d0,PruefeErlaubt
 move.l (sp)+,a0
 move.l #3,d0
 move.l #$1000,d1
 clr.l d3
PruefeWandel:
 clr.l d2
 move.b (a0)+,d2
 subi.b #48,d2
 cmpi.b #9,d2
 bls.S PruefeWandel2
 subi.b #39,d2
PruefeWandel2:
 mulu d1,d2
 add.l d2,d3
 divu #16,d1
dbra d0,PruefeWandel
 move.l d3,d0
rts
PruefeFehler:
 move.l (sp)+,a0
 move.l #$f0000000,d0
rts


ListCopper:
 clr.l d0
 clr.l d1
 move.w SchieberPos,d1
 move.w SchieberSchritt,d0
 divs d0,d1
 andi.l #$ffff,d1
 move.l d1,SchieberAktuell
 mulu #4,d1
 move.l CListStart,a0
 add.l d1,a0
 move.l ZeilenZahl,d3
 clr.l d0
 clr.l d1
ListCopper1:
 clr.l d0
 clr.l d1
 move.w (a0)+,d0
 move.w (a0)+,d1
 move.l a0,-(sp)
 btst #0,d0
beq.L ListMove
 move.l #"WAIT",Co1Name
 btst #0,d1
 beq.S ListWait
 move.l #"SKIP",Co1Name
ListWait:
 move.l d0,d2
 andi.w #$ff,d2
 andi.w #$ff00,d0
 divu #$100,d0
 movem.l d0-d3/a0,-(sp)
 move.l d0,d1
 move.l #100,d2
 lea.l VerText,a0
 bsr.L DezConvert
 movem.l (sp)+,d0-d3/a0
 movem.l d0-d3/a0,-(sp)
 move.l d2,d1
 move.l #100,d2
 lea.l HorText,a0
 bsr.L DezConvert
 movem.l (sp)+,d0-d3/a0
 move.l d1,d0
 move.l d1,d2
 andi.w #$7f00,d0
 divu #$100,d0
 andi.w #$ff,d2
 move.b #"1",BFDText
 btst #15,d1
 bne.S BFDSet
 move.b #"0",BFDText
BFDSet: 
 movem.l d0-d3/a0,-(sp)
 move.l d0,d1
 move.l #100,d2
 lea.l VerMask,a0
 bsr.L DezConvert
 movem.l (sp)+,d0-d3/a0
 movem.l d0-d3/a0,-(sp)
 move.l d2,d1
 move.l #100,d2
 lea.l HorMask,a0
 bsr.L DezConvert
 movem.l (sp)+,d0-d3/a0
 move.l d3,-(sp)
 move.l GfxBase,a6
 move.l #0,d0
 move.l RastPort,a1
 jsr SetAPen(a6)
 move.l #3,d0
 move.l RastPort,a1
 jsr SetBPen(a6)
 move.l (sp)+,d3
 lea.l Co1Text,a0
 move.l #Co1End-Co1Text,d0
 bra.L ListIt
ListMove:
 movem.l d0-d3,-(sp)
 move.l #$100,d1
 move.l #16,d2
 move.l #1,d3
 lea.l RegText,a0
 bsr.L ConvertAlles
 movem.l (sp)+,d0-d3
 movem.l d0-d3,-(sp)
 move.l d1,d0
 move.l #$1000,d1
 move.l #16,d2
 move.l #00,d3
 lea.l DatText,a0
 bsr.L ConvertAlles
 movem.l (sp)+,d0-d3
 lea NulName,a0
 cmpi.l #1,NamenFlag
 bne.S NamePrint
 subi.l #$40,d0
 lsl #2,d0
 lea RegName,a0
 add.l d0,a0
NamePrint:
 lea.l Re2Text,a1
 move.l (a0)+,(a1)+
 move.l (a0)+,(a1)+
 move.l d3,-(sp)
 move.l GfxBase,a6
 move.l #2,d0
 move.l RastPort,a1
 jsr SetAPen(a6)
 move.l #1,d0
 move.l RastPort,a1
 jsr SetBPen(a6)
 move.l (sp)+,d3
 lea.l Co2Text,a0
 move.l #Co2End-Co2Text,d0
ListIt:
 move.l d3,-(sp)
 movem.l a0/d0,-(sp)
 move.l d3,d0
 move.l ZeilenZahl,d1
 sub.l d0,d1
 mulu #9,d1
 addi.l #17,d1
 move.l #4,d0
 move.l RastPort,a1
 jsr Move(a6)
 movem.l (sp)+,a0/d0
 move.l RastPort,a1
 jsr Text(a6)
 move.l (sp)+,d3
 move.l (sp)+,a0
 dbra d3,ListCopper1
rts

GadgetsRefresh:
 move.l IntBase,a6
 move.l Window,a1
 move.l #0,a2
 move.l 62(a1),a0
 jsr RefreshGadgets(a6)
rts

GetIDCMP:
 move.l ExecBase,a6
 move.l UserPort,a0
 jsr GetMsg(a6)
rts 

DezConvert:
 move.l a0,-(sp)
DezConvert2:
 divu d2,d1
 addi.w #48,d1
 move.b d1,(a0)+
 clr.w d1
 swap d1
 cmp.l #1,d2
 beq.S DezConvertEnd1
 divu #10,d2
bra.S DezConvert2
DezConvertEnd1:
 move.l (sp)+,a0
DezConvertLoop:
 cmpi.b #48,(a0)
 bne.S DezConvertEnd2
 move.b #32,(a0)+
bra.S DezConvertLoop
DezConvertEnd2:
rts

ConvertAlles:
 movem.l d0-d5,-(sp)
 move.l MatBase,a6
ConvertLoop1:
 move.l d0,d4
 move.l d1,d5
 bsr.S ConvertDivide
 move.l d5,d0
 tst.b d4
 bne.S ConvertNoZeros1
 btst #1,d3
 beq.S ConvertNoZeros2
 move.b #" ",d4
 bra.S ConvertNoHex
ConvertNoZeros1:
 bclr #1,d3
ConvertNoZeros2:
 addi.b #48,d4
 cmpi.b #57,d4
 bls.S ConvertNoHex
 addi.b #7,d4
 btst #0,d3
 bne.S ConvertNoHex
 addi.b #32,d4
ConvertNoHex:
 move.b d4,(a0)+
 cmpi.l #1,d1
 beq.S ConvertEnd
 move.l d1,d4
 move.l d2,d5
 bsr.S ConvertDivide
 move.l d4,d1
bra.S ConvertLoop1
ConvertEnd:
 movem.l (sp)+,d0-d5
rts

ConvertDivide:
 movem.l d0-d3,-(sp)
   move.l d4,d0
   move.l d5,-(sp)
     jsr SPFlt(a6)
   move.l (sp)+,d1
   move.l d0,-(sp)
     move.l d1,d0
     jsr SPFlt(a6)
     move.l d0,d1
   move.l (sp)+,d0
   move.l d0,-(sp)
     jsr SPDiv(a6)
     move.l d1,-(sp)
       jsr SPFix(a6)
       jsr SPFlt(a6)
     move.l (sp)+,d1
     move.l d0,d2
     jsr SPMul(a6)
     move.l d0,d1
   move.l (sp)+,d0
   jsr SPSub(a6)
   jsr SPFix(a6)
   move.l d0,-(sp)
   move.l d2,d0
   jsr SPFix(a6)
   move.l (sp)+,d5
 move.l d0,d4
 movem.l (sp)+,d0-d3
rts

InitAusgabe:
 move.l GfxBase,a6
 move.l 50(a6),CListStart
 move.l CListStart,a5
InitAusgabe1:
 move.l (a5)+,d0
 btst #16,d0
beq.S InitAusgabe1
 swap d0
 andi.l #$ff,d0
 cmpi.b #$e4,d0
bls.S InitAusgabe1
 subq.l #4,a5
 move.l a5,CListEnde
 move.l CListStart,a0
 sub.l a0,a5
 move.l a5,d0
 divu #4,d0
 addi.l #1,d0
 move.l d0,CListLaenge
 subi.l #1,d0
 subi.l ZeilenZahl,d0
 move.l #65535,d1
 divu d0,d1
 andi.l #$ffff,d1
 move.w d1,SchieberSchritt
rts

InitFenster:
 move.l IntBase,a6
 lea.l NewWindow,a0
 jsr OpenWindow(a6)
 tst.l d0
 beq.S FensterFehler
 move.l d0,Window
 move.l d0,a0
 move.l 50(a0),RastPort
 move.l 86(a0),UserPort
rts
FensterFehler:
 move.l (sp)+,a0
bra.L Ende2

SchliesseWindow:
 move.l IntBase,a6
 move.l Window,a0
 jsr CloseWindow(a6)
rts

OeffneLibraries:
 move.l ExecBase,a6
 lea.l IntName,a1
 jsr OldOpenLibrary(a6)
 move.l d0,IntBase
 lea.l GfxName,a1
 jsr OldOpenLibrary(a6)
 move.l d0,GfxBase
 lea.l MatName,a1
 jsr OldOpenLibrary(a6)
 move.l d0,MatBase
rts

SchliesseLibraries:
 move.l ExecBase,a6
 move.l IntBase,a1
 jsr CloseLibrary(a6)
 move.l GfxBase,a1
 jsr CloseLibrary(a6)
 move.l MatBase,a1
 jsr CloseLibrary(a6)
rts

align 4
Window:      dc.l 0
IntBase:     dc.l 0
MatBase:     dc.l 0
GfxBase:     dc.l 0
RastPort:    dc.l 0
UserPort:    dc.l 0
CListStart:  dc.l 0
CListEnde:   dc.l 0
CListLaenge: dc.l 40
NamenFlag:   dc.l 1
ZeilenZahl:  dc.l 15
SchieberAktuell:  dc.l 0
EditierteAdresse: dc.l 0

IntName: dc.b 'intuition.library',0
MatName: dc.b 'mathffp.library',0
GfxName: dc.b 'graphics.library',0
WinName: dc.b "The Copper Monitor  (C) 1988 by S.Kemeny",0
In1Text: dc.b "Copper Information Service",0
In2Text: dc.b "Anfangsadresse der Copperliste:    $"
In2Data: dc.b "000000",0
In3Text: dc.b "Endadresse der Copperliste:        $"
In3Data: dc.b "000000",0
In4Text: dc.b "Anzahl der Befehle in der Copperliste:  "
In4Data: dc.b "0000",0
In5Text: dc.b "Befehlswort 1",0
In6Text: dc.b "Befehlswort 2",0
Bo2Text: dc.b "O.K.",0

even
St1Puff: dc.b "0000",0,0
Un1Puff: dc.b "0000",0,0
St2Puff: dc.b "0000",0,0
Un2Puff: dc.b "0000",0,0,0
Co1Text: dc.b 32
Co1Name: dc.b "WAIT  Y="
VerText: dc.b " 00, X="
HorText: dc.b " 00, BFD="
BFDText: dc.b "1, VMask="
VerMask: dc.b " 00, HMask="
HorMask: dc.b " 00"
Co1End:

even
Co2Text: dc.b " MOVE  #$"
DatText: dc.b "0000 into $DFF"
RegText: dc.b "000",32,32,32,32,32,32
Re2Text: blk.b 16,32
Co2End:

even
RegName:
 dc.b " BLTCON0 BLTCON1 BLTAFWM BLTALWM BLTCPTH BLTCPTL BLTBPTH"
 dc.b " BLTBPTL BLTAPTH BLTAPTL BLTDPTH BLTDPTL BLTSIZE  UNUSED"
 dc.b "  UNUSED  UNUSED BLTCMOD BLTBMOD BLTAMOD BLTDMOD  UNUSED"
 dc.b "  UNUSED  UNUSED  UNUSED BLTCDAT BLTBDAT BLTADAT  UNUSED"
 dc.b "  UNUSED  UNUSED  UNUSED DSKSYNC COP1LCH COP1LCL COP2LCH"
 dc.b " COP2LCL COPJMP1 COPJMP2  COPINS DIWSTRT DIWSTOP DDFSTRT"
 dc.b " DDFSTOP  DMACON  CLXCON  INTENA  INTREQ  ADKCON"
 dc.b " AUD0LCH AUD0LCL AUD0LEN AUD0PER AUD0VOL AUD0DAT  UNUSED"
 dc.b "  UNUSED AUD1LCH AUD1LCL AUD1LEN AUD1PER AUD1VOL AUD1DAT"
 dc.b "  UNUSED  UNUSED AUD2LCH AUD2LCL AUD2LEN AUD2PER AUD2VOL"
 dc.b " AUD2DAT  UNUSED  UNUSED AUD3LCH AUD3LCL AUD3LEN AUD3PER"
 dc.b " AUD3VOL AUD3DAT  UNUSED  UNUSED BPL1PTH BPL1PTL BPL2PTH"
 dc.b " BPL2PTL BPL3PTH BPL3PTL BPL4PTH BPL4PTL BPL5PTH BPL5PTL"
 dc.b " BPL6PTH BPL6PTL  UNUSED  UNUSED  UNUSED  UNUSED BPLCON0"
 dc.b " BPLCON1 BPLCON2  UNUSED BPL1MOD BPL2MOD  UNUSED  UNUSED"
 dc.b " BPL1DAT BPL2DAT BPL3DAT BPL4DAT BPL5DAT BPL6DAT  UNUSED"
 dc.b "  UNUSED SPR0PTH SPR0PTL SPR1PTH SPR1PTL SPR2PTH SPR2PTL"
 dc.b " SPR3PTH SPR3PTL SPR4PTH SPR4PTL SPR5PTH SPR5PTL SPR6PTH"
 dc.b " SPR6PTL SPR7PTH SPR7PTL SPR0POS SPR0CTL SP0DATA SP0DATB"
 dc.b " SPR1POS SPR1CTL SP1DATA SP1DATB SPR2POS SPR2CTL SP2DATA"
 dc.b " SP2DATB SPR3POS SPR3CTL SP3DATA SP3DATB SPR4POS SPR4CTL"
 dc.b " SP4DATA SP4DATB SPR5POS SPR5CTL SP5DATA SP5DATB SPR6POS"
 dc.b " SPR6CTL SP6DATA SP6DATB SPR7POS SPR7CTL SP7DATA SP7DATB"
 dc.b " COLOR00 COLOR01 COLOR02 COLOR03 COLOR04 COLOR05 COLOR06"
 dc.b " COLOR07 COLOR08 COLOR09 COLOR10 COLOR11 COLOR12 COLOR13"
 dc.b " COLOR14 COLOR15 COLOR16 COLOR17 COLOR18 COLOR19 COLOR20"
 dc.b " COLOR21 COLOR22 COLOR23 COLOR24 COLOR25 COLOR26 COLOR27"
 dc.b " COLOR28 COLOR29 COLOR30 COLOR31"
NulName: blk.b 8,32

NewWindow:
 dc.w 3,11,408,156,$0102
 dc.l $228,$1100e,SchieberGadget,0,WinName,0,0,0,0
 dc.w 1
SchieberGadget:
 dc.l BoolGadget1
 dc.w -16,10,17,-21,87,2,3
 dc.l SchieberImage,0,0,0,SchieberSpecial,$1000
 dc.w 0
SchieberImage:
 dc.w 0,0,9,16,1
 dc.l SchieberData,$02000000
 dc.w 0
SchieberData:
 dc.w $ff80
 blk.w 14,$c180
 dc.w $ff80
SchieberSpecial:
 dc.w 4,0
SchieberPos:
 dc.w 0,0
SchieberSchritt:
 dc.w $666,0,0,0,0,0,0
BoolGadget1:
 dc.w 0,0,-16,-10,16,10,158,$102,1
 dc.l BoolGadget1Image1,BoolGadget1Image2,0,0,0,$20000
 dc.w 0
BoolGadget1Image1:
 dc.w 0,0,15,10,1
 dc.l Bool1Image1Data,$01020000
 dc.w 0
Bool1Image1Data:
 dc.w $7fff
 blk.w 9,$6003
BoolGadget1Image2:
 dc.w 0,0,15,10,1
 dc.l Bool1Image2Data,$01030000
 dc.w 0
Bool1Image2Data:
 dc.w $7fff
 dc.w $6003,$6633,$6733,$67b3,$66b3,$66f3,$6673,$6633,$6003
BoolGadget2:
 dc.w 0,0,324,128,32,8,0,2,1
 dc.l Bool2Border,0,Bool2Text,0,0,$50000
Bool2Border:
 dc.l 0,$02020005,Bool2BorderData,0
Bool2BorderData:
 dc.w -2,-2,34,-2,34,9,-2,9,-2,-2
Bool2Text:
 dc.l $02030100,0,0,Bo2Text,0
EditRequester1:
 dc.w 0,0,4,11,384,144,0,0
 dc.l StringGadget1,0,InfoText1,$00000100,0,0,0
InfoText1:
 dc.b 2,0,0,0
 dc.w 94,6
 dc.l 0,In1Text,InfoText2
InfoText2:
 dc.b 2,0,0,0
 dc.w 24,26
 dc.l 0,In2Text,InfoText3
InfoText3:
 dc.b 2,0,0,0
 dc.w 24,37
 dc.l 0,In3Text,InfoText4
InfoText4:
 dc.b 2,0,0,0
 dc.w 17,58
 dc.l 0,In4Text,InfoText5
InfoText5:
 dc.b 3,2,1,0
 dc.w 56,88
 dc.l 0,In5Text,InfoText6
InfoText6:
 dc.b 3,2,1,0
 dc.w 224,88
 dc.l 0,In6Text,0
StringGadget1:
 dc.l StringGadget2
 dc.w 84,102,48,8,0,$202,4
 dc.l BorderGadget1,0,0,0,StringSpecial1,$30000
 dc.w 0
BorderGadget1:
 dc.l 0,$03030005,Border1Data,0
Border1Data:
 dc.w -2,-2,50,-2,50,9,-2,9,-2,-2
StringSpecial1:
 dc.l St1Puff,Un1Puff,5,0,0,0,0,0,0
StringGadget2:
 dc.l BoolGadget2
 dc.w 252,102,48,8,0,$202,4
 dc.l BorderGadget2,0,0,0,StringSpecial2,$40000
 dc.w 0
BorderGadget2:
 dc.l 0,$03030005,Border2Data,0
Border2Data:
 dc.w -2,-2,50,-2,50,9,-2,9,-2,-2
StringSpecial2:
 dc.l St2Puff,Un2Puff,5,0,0,0,0,0,0
