;DESQUEZE.ASM VER13
;1983-12-28
;Av Mikael Pettersson, alias Pi
;Sk{nkt till ABC-klubben av densamme 870411
;F}r fritt anv{ndas av klubbens medlemmar f|r icke-kommerciella {ndam}l 
BUF EQU 32768
 ORG 63488 ;BUF3-7
 LD BC,256+15
 PUSH BC
 CALL VAR
 LD (65306),BC
 POP BC
 CALL FN
 CALL FIL?
 CALL 68
B\RJAN PUSH HL
 LD HL,BUF+255
 LD (65306),HL
 LD DE,BUF
 POP HL
 PUSH DE
 PUSH HL
 CALL ADR
 POP HL
LOOP1 CALL SPACE
 LD A,(HL)
 CP 148
 CALL Z,MINSKA
 CP 129
 CALL Z,MINSKA
 CP 188
 JP Z,K188
 CP 135
 JP Z,F[RDIG
 CP 192
 JP NC,FLIST
 CP 128
 JP C,ASCII
 CP 183
 JP Z,K183
 CALL SPACE
 LD A,(HL)
 INC HL
 LD B,1
 CP 191
 JR NZ,A0
 LD B,(HL)
 INC HL
 LD A,(HL)
 INC HL
 CP 129
 JR NZ,A0
 DEC A
A0 LD C,A
 PUSH BC
 CALL BCTAB
 CP 157
 JR C,A1
 CP 160
 JR NC,A1
 ADD A,230
A1 CP 134
 JR NZ,A2
 LD BC,(65405)
 CALL RUT1
 JR A3
A2 CALL SUB1
A3 POP BC
 CALL SPACE
 LD A,C
 CP 134
 JP C,RADNR
 PUSH HL
 LD HL,JPTAB-1
 LD BC,13
 CPDR
 LD A,C
 POP HL
 JR NZ,NEJ
 LD BC,JPTAB
 PUSH HL
 LD L,A
 ADD HL,HL
 LD H,0
 ADD HL,BC
 PUSH DE
 LD E,(HL)
 INC HL
 LD D,(HL)
 EX DE,HL
 POP DE
 EX (SP),HL
 RET
NEXT LD A,7
 CALL VLIST
 JR NEJ
WHILE INC HL
 INC HL
FOR JP LOOP1
WEND INC HL
 INC HL
 JR NEJ
L? DEC DE
 DEC DE
 LD A,(DE)
 DEC DE
 LD (DE),A
 INC DE
 JR REM
DATA INC HL
 INC HL
REM LD C,(HL)
 LD B,0
 INC HL
 LDIR
 DEC HL
 DEC DE
 JR NEJ
MID DEC DE
FLIST CALL LISTF
 DEC HL
 DEC HL
 LD A,(HL)
 INC HL
 INC HL
 CP 189
 JR C,NEJ
 CP 191
 JR NC,NEJ
 CP 190
 JR NZ,REDAN
 PUSH HL
 LD HL,THEN
 LD BC,4
 LDIR
 POP HL
REDAN CALL SPACE
 DEC HL
ELSE LD C,(HL)
 LD B,0
 PUSH HL
 ADD HL,BC
 LD A,83
 LD (DE),A
 INC DE
 CALL ADR
 POP HL
 INC HL
NEJ JR ASCII-2
K188 INC HL
 INC HL
 INC HL
 JR F[RDIG
K183 LD B,0
 INC HL
A6 INC B
 BIT 2,(HL)
 INC HL
 JR Z,A6
A8 PUSH BC
 CALL LISTF
 POP BC
 DJNZ A7
 LD A,(HL)
 CP 183
 JR NZ,F[RDIG
A7 CALL KOMMA
 INC B
 DJNZ A8
 JR F[RDIG
ASCII LDI
 JP LOOP1+3
A9 CALL KOMMA
RADNR PUSH BC
 LD C,(HL)
 INC HL
 LD B,(HL)
 PUSH HL
 BIT 0,(IY+38)
 JR Z,EJFIX
 ADD HL,BC
 JR A5
EJFIX LD H,B
 LD L,C
A5 CALL ADR
 POP HL
 INC HL
 POP BC
 DJNZ A9
 JR F[RDIG
DEFFN DEC DE
 INC HL
 INC HL
 CALL RUT2
 INC HL
 INC HL
 LD (65320),HL
 LD A,(HL)
 INC HL
 AND A
 JR Z,A10
 LD B,A
 LD A,40
 LD (DE),A
 INC DE
 LD C,0
 CALL RUT3
 LD A,41
 LD (DE),A
 INC DE
A10 LD A,(HL)
 ADD A,64
 JR NC,F[RDIG
 LD A,61
 LD (DE),A
 INC DE
 CALL LISTF
FNEND PUSH HL
 LD HL,0
 LD (65320),HL
 LD (65322),HL
 POP HL
 JR F[RDIG
BL[ LD C,2
 CALL RUT3-2
F[RDIG EX (SP),HL
 CALL SKRIV
 CALL 2
 CP 13
 JP Z,KOMRUT
 POP HL
 LD A,(HL)
 CP 135
 JP NZ,B\RJAN
 INC HL
 PUSH HL
 LD HL,BUF+255
 LD (65306),HL
 LD DE,BUF
 POP HL
 PUSH DE
 PUSH HL
 CALL ADR
 POP HL
 LD A,(HL)
 CP 1
 JR Z,SLUT
 CALL BCHL1+1
 PUSH HL
 LD H,B
 LD L,C
 JP LOOP1-4
SKRIV EX DE,HL
 LD (HL),13
 INC HL
 LD (HL),10
 INC HL
 AND A
 SBC HL,DE
 LD B,H
 LD C,L
 EX DE,HL
 LD A,(FLAG)
 AND A
 JR Z,CON
 PUSH HL
 PUSH BC
 LD IX,MAP
 CALL PRT
 POP BC
 POP HL
CON CALL 11
 RET
SLUT EX DE,HL
 LD (HL),69
 INC HL
 LD (HL),80
 INC HL
 EX DE,HL
 POP HL
 CALL SKRIV
 JP KOMRUT
SPACE LD A,32
 EX DE,HL
 DEC HL
 CP (HL)
 INC HL
 EX DE,HL
 RET Z
 LD (DE),A
 INC DE
 RET
ADR LD A,40
 LD (DE),A
 INC DE
 CALL BINASC
 LD A,41
 LD (DE),A
 INC DE
 RET
MINSKA DEC (HL)
 LD A,(HL)
 RET
VAR LD HL,(65326)
LOP1 LD A,H
 OR L
 RET Z
 LD E,(HL)
 INC HL
 LD D,(HL)
 INC HL
 PUSH DE
 CALL TYP
 POP HL
 JR LOP1
FN LD HL,(65286)
 LD DE,16
 ADD HL,DE
LOP3 LD E,(HL)
 INC HL
 LD D,(HL)
 LD A,D
 OR E
 RET Z
 ADD HL,DE
 PUSH HL
 INC HL
 INC HL
 CALL TYP
 PUSH BC
 LD BC,(65306)
 INC HL
 INC HL
 LD A,(HL)
 INC HL
 AND A
 JR Z,NOARG
LOP4 PUSH AF
 CALL TYP
 POP AF
 DEC A
 JR NZ,LOP4
NOARG LD A,(HL)
 INC HL
 CP 182
 JR NZ,NOLOC
 LD A,(HL)
 INC HL
 AND A
 JR Z,NOLOC
LOP5 PUSH AF
 CALL TYP
 LD A,D
 CP 2
 JR NZ,NOSTR
 INC HL
 INC HL
NOSTR POP AF
 DEC A
 JR NZ,LOP5
NOLOC POP BC
 POP HL
 JR LOP3
TYP LD A,C
 SLA A
 SLA A
 SLA A
 LD E,A
 LD A,(HL)
 AND 7
 LD D,A
 OR E
 LD (HL),A
 INC HL
 LD (HL),B
 INC HL
 INC B
 LD A,B
 CP 30
 RET C
 LD B,1
 LD A,C
 INC C
 CP 15
 RET NZ
 LD C,0
 RET
 DEFB 140
 DEFB 138
 DEFB 182
 DEFB 143
 DEFB 142
 DEFB 154
 DEFB 155
 DEFB 141
 DEFB 152
 DEFB 153
 DEFB 144
 DEFB 162
 DEFB 139
JPTAB DEFW DEFFN
 DEFW ELSE
 DEFW BL[
 DEFW REM
 DEFW DATA
 DEFW WHILE
 DEFW WEND
 DEFW FNEND
 DEFW FOR
 DEFW NEXT
 DEFW REM
 DEFW MID
 DEFW L?
THEN DEFM "THEN"
BINASC XOR A
 LD BC,55536
 CALL BINA2
 LD BC,64536
 CALL BINA2
 LD BC,65436
 CALL BINA2
 LD C,246
 CALL BINA2
 LD A,L
 JR BINA4
BINA2 PUSH DE
 LD E,255
BINA3 INC E
 ADD HL,BC
 JR C,BINA3
 SBC HL,BC
 OR E
 POP DE
 RET Z
BINA4 OR 48
 LD (DE),A
 INC DE
 LD A,48
 RET
KOMMA LD A,44
 LD (DE),A
 INC DE
 RET
LOP11 LD A,(BC)
 CALL SUB1
 PUSH HL
 DEC HL
 LD L,(HL)
 LD H,0
 CALL BINASC
 POP HL
 RET
RUT1 LD A,(HL)
 INC HL
 PUSH HL
 CALL SUB2
 CALL BCHL1
 POP HL
 JR Z,LOP11
 ADD A,128
SUB1 PUSH HL
 LD H,B
 LD L,C
 CPIR
LOP13 LD A,(HL)
 ADD A,A
 JR C,LOP12
 JR Z,LOP12
 LD (DE),A
 LDI
 JR LOP13
LOP12 POP HL
 RET
SUB2 PUSH DE
 LD E,A
LOP14 LD A,B
 OR C
 JR Z,LOP15
 LD H,B
 LD L,C
 CALL BCHL2
 LD A,E
 SUB (HL)
 INC HL
 CP (HL)
 JR NC,LOP14
LOP15 POP DE
 INC HL
 RET
SUB3 PUSH HL
 JR LOP13
RUT2 CALL BCHL2
 PUSH HL
 PUSH BC
 PUSH DE
 LD L,C
 LD H,B
 LD B,3
LOP20 SRL H
 RR L
 DJNZ LOP20
 LD BC,1023
 AND A
 SBC HL,BC
 JR C,LOP23
 EX DE,HL
 CALL SUB4
 EXX
 ADD HL,BC
 ADD HL,DE
 POP DE
 CALL SUB3
 LD C,6
 LD A,249
 AND (IY+29)
 OR C
 LD (IY+29),A
 EX DE,HL
 POP BC
LOP21 LD (HL),36
 BIT 1,C
 JR NZ,LOP22
 LD (HL),37
 LD A,C
 RRCA
 BIT 0,(IY+29)
 JR Z,LOP22-2
 LD (HL),46
 CCF
 JR NC,LOP22+1
LOP22 INC HL
 EX DE,HL
 POP HL
 XOR A
 RET
LOP23 ADD HL,BC
 LD A,L
 POP HL
 POP BC
 SET 6,B
 LD (HL),B
 INC HL
 AND 15
 CP 15
 JR Z,LOP21
 OR 48
 LD (HL),A
 INC HL
 JR LOP21
BCHL1 INC HL
 INC HL
BCHL2 LD C,(HL)
 INC HL
 LD B,(HL)
 INC HL
 RET
SUB4 CALL SUB5
 PUSH HL
 EXX
 POP HL
 CALL BCHL1
 EX DE,HL
 AND A
 SBC HL,BC
 EX DE,HL
 EXX
 RET
SUB5 EXX
 LD HL,(65288)
 LD B,(HL)
 DEC HL
 LD C,(HL)
 ADD HL,BC
 POP IX
 LD DE,65535
 XOR A
LOP24 PUSH HL
 PUSH DE
 CALL JPIX
 POP DE
 POP HL
 RET C
 LD C,(HL)
 INC HL
 LD B,(HL)
 LD A,B
 OR C
 RET Z
 EX DE,HL
 DEC HL
 SBC HL,BC
 ADD HL,BC
 INC HL
 EX DE,HL
 JR NC,LOP25
 LD A,B
 CP (IY+15)
 JR NC,LOP25
 LD (HL),0
 DEC HL
 LD (HL),0
LOP25 LD H,B
 LD L,C
 JR LOP24
JPIX JP (IX)
 LD B,(HL)
 INC HL
RUT3 PUSH BC
 LD A,(HL)
 PUSH AF
 CALL RUT2
 POP AF
 POP BC
 AND 2
 JR Z,LOP26
 BIT 1,C
 JR Z,LOP26
 PUSH BC
 CALL BCHL2
 PUSH HL
 LD H,B
 LD L,C
 LD A,61
 LD (DE),A
 INC DE
 CALL BINASC
 POP HL
 POP BC
LOP26 CALL KOMMA
 DJNZ RUT3
 DEC DE
 RET
FLAG DEFB 0
MAP DEFM "      "
 DEFM "         "
 DEFM "         "
FR]GA DEFB 13
 DEFB 10
 DEFM "FILNAMN "
 DEFM "(RET=BAR"
 DEFM "A CON:)?"
FIL? XOR A
 LD (FLAG),A
 LD HL,FR]GA
 LD BC,26
 CALL 11
 LD HL,BUF
 LD BC,30
 PUSH HL
 CALL 5
 CALL CRLF
 POP HL
 DEC HL
 RST 24
 LD A,(HL)
 LD C,20
 CALL 105
 LD IX,MAP
 LD (IX+22),C
 LD (IX+23),0
 CP 13
 RET Z
 LD A,3
 LD (FLAG),A
 CALL 93
 RET
CRLF PUSH HL
 PUSH BC
 LD HL,FR]GA
 LD BC,2
 CALL 11
 POP BC
 POP HL
 RET
KOMRUT LD HL,MAP
 LD DE,65379
 LD BC,24
 LDIR
 CALL 105
 JP 268           ;b|rjan till kommandoloopen
PRT JP 4506       ;skriver en rad p} filen utpekad av IX
VLIST JP 15823    ;listar variabel
LISTF JP 15712    ;listar funktion(?)
BCTAB LD BC,2370  ;instruktionstabell, b|rjar med 134,88,83,84,77,0,145...
 RET
