1 REM Ins{nd av Bengt Holgersson <559>    1986-02-02 14.06.46
        ORG 0F900H

        JP    FGPNT
        JP    FGLINE
MINNE:  DEFW  0

FGPNT:  LD (OLDCOR),DE
FGPONT: PUSH DE                 ;INHOPP FR]N FGLINE
        CALL SCRDOT             ;RITA P] SK[RMEN
        LD A,D
        SRL D
        SRL D
        SRL D
        LD HL,(MINNE)
        ADD HL,DE
        AND 7
        INC A
        LD B,A
        XOR A
        SCF
LOOP:   RL A
        DJNZ LOOP
        NOP                     ;<- SETDOT  CLRDOT = CPL
        OR (HL)                 ;<- SETDOT  CLRDOT = AND (HL)
        LD (HL),A
        POP DE
        RET

FGLINE: CALL FGPONT             ;S[TT SISTA PUNKTEN
        LD      HL,(OLDCOR)     ;H[MTA GAMMAL KOORDINAT
        EX      DE,HL           ;HL=NY  DE=GAMMAL
        LD      (OLDCOR),HL     ;LAGRA NY KOORDINAT

        LD      A,1             ;S[TT COLSTP OCH ROWSTP TILL 1
        LD      (COLSTP),A
        LD      (ROWSTP),A
        LD      A,H             ;BER[KNA ROWDIF  NY-GAMMAL
        SUB     D
        LD      (ROWDIF),A
        JR      NC,COLUMN
        NEG                     ;BYT TECKEN
        LD      (ROWDIF),A
        LD      A,-1            ;S[TT ROWSTP TILL -1
        LD      (ROWSTP),A
COLUMN: LD      A,L             ;BER[KNA COLDIF  NY-GAMMAL
        SUB     E
        LD      (COLDIF),A
        JR      NC,ZCHECK
        NEG                     ;BYT TECKEN
        LD      (COLDIF),A
        LD      A,-1            ;S[TT COLSTP TILL -1
        LD      (COLSTP),A

ZCHECK: LD      A,(COLDIF)      ;KOLLA OM COLDIF = 0
        CP      0
        JR      NZ,SIZCHK
        LD      A,(ROWDIF)      ;KOLLA OM ROWDIF = 0
        CP      0
        RET     Z               ;RETUR OM B]DA = 0

SIZCHK: LD      A,(COLDIF)      ;KOLLA OM COLDIF ELLER ROWDIF [R ST\RST
        LD      B,A
        LD      A,(ROWDIF)
        SUB     B
        JR      NC,LINE2

LINE1:  LD      A,(COLDIF)      ;COLDIF ST\RST
        SRL     A               ;/2
        LD      B,A
        LD      A,(ROWDIF)
        SUB     B
        LD      (TEST),A        ;TEST=ROWDIF-COLDIF/2
        LD      A,0
        SBC     A,0
        LD      (FLAG),A        ;FLAG=TECKEN
        LD      A,(COLDIF)
        LD      B,A             ;TOTALT ANTAL PUNKTER
NEXT1:  PUSH    BC
        CALL    FGPONT
        LD      A,(FLAG)        ;KOLLA TECKEN P] TEST
        AND     80H
        JR      NZ,SINGL1

DOUBL1: LD      A,(ROWDIF)      ;TEST POSITIV
        LD      B,A
        LD      A,(COLDIF)
        SUB     B               ;SINGLE
        LD      B,A
        LD      A,(TEST)
        SUB     B
        LD      (TEST),A        ;TEST=TEST-SINGLE
        LD      A,(FLAG)
        SBC     A,0
        LD      (FLAG),A        ;FLAG=TECKEN
        LD      A,(ROWSTP)
        ADD     A,D
        LD      D,A
        JR      CONT1

SINGL1: LD      A,(ROWDIF)      ;TEST NEGATIV
        LD      B,A
        LD      A,(TEST)
        ADD     A,B
        LD      (TEST),A        ;TEST=TEST+DOUBLE
        LD      A,(FLAG)
        ADC     A,0
        LD      (FLAG),A        ;FLAG=TECKEN
CONT1:  LD      A,(COLSTP)
        ADD     A,E
        LD      E,A
        POP     BC
        DJNZ    NEXT1
        RET

LINE2:  LD      A,(ROWDIF)      ;ROWDIF ST\RST
        SRL     A
        LD      B,A
        LD      A,(COLDIF)
        SUB     B
        LD      (TEST),A        ;TEST=COLDIF-ROWDIF/2
        LD      A,0
        SBC     A,0
        LD      (FLAG),A        ;FLAG=TECKEN
        LD      A,(ROWDIF)
        LD      B,A             ;TOTALT ANTAL PUNKTER
NEXT2:  PUSH    BC
        CALL    FGPONT
        LD      A,(FLAG)        ;KOLLA TECKEN P] TEST
        AND     80H
        JR      NZ,SINGL2

DOUBL2: LD      A,(COLDIF)      ;TEST POSITIV
        LD      B,A
        LD      A,(ROWDIF)
        SUB     B               ;SINGLE
        LD      B,A
        LD      A,(TEST)
        SUB     B
        LD      (TEST),A        ;TEST=TEST-SINGLE
        LD      A,(FLAG)
        SBC     A,0
        LD      (FLAG),A        ;FLAG=TECKEN
        LD      A,(COLSTP)
        ADD     A,E
        LD      E,A
        JR      CONT2

SINGL2: LD      A,(COLDIF)      ;TEST NEGATIV
        LD      B,A
        LD      A,(TEST)
        ADD     A,B
        LD      (TEST),A        ;TEST=TEST+DOUBLE
        LD      A,(FLAG)
        ADC     A,0
        LD      (FLAG),A        ;FLAG=TECKEN
CONT2   LD      A,(ROWSTP)
        ADD     A,D
        LD      D,A
        POP     BC
        DJNZ    NEXT2
        RET

OLDCOR: DEFW    0
COLDIF: DEFB    0
ROWDIF: DEFB    0
COLSTP: DEFB    0
ROWSTP: DEFB    0
TEST:   DEFB    0
FLAG:   DEFB    0

SCRDOT: PUSH    DE         ;D=RAD E=KOLUMN
        LD      A,(590)    ;TKN 80 ?
        CP      80
        JR      Z,WIDE
        SRL     E          ;/2
WIDE:   SRL     E          ;/2
        LD      A,2        ;\KA KOLUMN MED 2 (START GRAFIK)
        ADD     A,E
        LD      E,A
        SRL     D          ;/2
        SRL     D          ;/2
        LD      A,03FH     ;V[ND UPP OCH NED P] RADER
        SUB     D
        LD      C,A      ;RAD I C-REG
        LD      A,(022F7H)
        CP      6
        LD      A,E      ;KOLUMN I A-REG
        JR      Z,OLD
        CALL    022F5H   ;NYA CHECKSUMMOR
        JR      SETIT
OLD:    CALL    022F7H   ;GAMMAL CHECKSUMMA
SETIT:  OR      (HL)
        OR      32
        LD      (HL),A
        POP     DE
        RET

        END
