title LANGUAGE utility name ('LANGUAGE') ; The AMSTRAD LANGUAGE utility for PCW machines ; Disassembled by W.Cirsovius ; Call: LANGUAGE option OS equ 0000h BDOS equ 0005h CCPcmd equ 0080h _Conout equ 2 _Condir equ 6 _String equ 9 _vers equ 12 CPM31 equ 31h CPM22 equ 22h CD.VERS equ 00e3h _Userf equ 30 LoMask equ 00001111b lf equ 0ah cr equ 0dh eot equ '$' esc equ 1bh eof equ 'Z'-'@' eos equ -1 ; End of table marker _IG equ 0 _HX equ 2 _NM equ 3 _EX equ 4 _EO equ 5 MSB equ 7 jr LANGUAGE db 'LANGUAGE #115',cr,lf db 'Developed by Locomotive Software Ltd.',cr,lf db 'Copyright (C) 1985 Amstrad ' db 'Consumer Electronics PLC',cr,lf ; ; %%%%%%%%%%%%%%%%%%%%%% ; %%% START LANGUAGE %%% ; %%%%%%%%%%%%%%%%%%%%%% ; LANGUAGE: ld (UsrStk),sp ; Save callers stack ld sp,LocStk ; Get local stack call GetVersion ; Get machine version call PrepCCPLine ; Prepare command line call c,ProcLANG ; Process language set up ld sp,(UsrStk) ; Get back stack ret ; ; Process language set up ; ENTRY Reg C holds macine type ; ProcLANG: ld a,c ; Test correct type cp 3 jp z,InvalEnv ; .. nope call GetNum ; Get number jr z,IllNum ld a,esc call Condir ; Give escape ld a,'2' call Condir ; .. give prefix ld a,l add a,' ' ; Add offset jr Condir ; .. define language IllNum: ld de,$BAD.NUM jp ProcErr ; Tell invalid number $BAD.NUM: db 'Bad number',cr,lf,eot ; ; Print character on console via BDOS ; ENTRY Accu holds character ; Condir: push hl push de push bc push af ld e,a ld c,_Condir call BDOS ; .. print pop af pop bc pop de pop hl ret ; ; Process error ; ENTRY Reg DE points to error message ; ProcErr: push bc push af call String ; Print error call GetAttr ; Test EOL or EOF jr nz,PE.ex ; .. yeap ld de,$IGNORE call String ; Tell ignoring jr PE.go PE.loop: ld a,c call Conout ; Print character PE.go: call GetChr ; Get character and attribute call GetAttr ; Test EOL or EOF call Get ; Get character jr z,PE.loop ; .. there is more to print ld de,$CRLF call String ; .. close line PE.ex: pop af pop bc ret $IGNORE: db 'Ignoring rest of line: ',eot $CRLF: db cr,lf,eot ; ; Tell invalid environment ; InvalEnv: push de ld de,$INVENV call String ; Print error pop de ret $INVENV: db 'This program will not run in this environment' db cr,lf,eot ; ; Print string on console ; ENTRY Reg DE points to string closed by '$' ; String: push hl push de push bc push af ld c,_String call BDOS ; .. print pop af pop bc pop de pop hl ret ; ; Print character on console ; ENTRY Accu holds character ; Conout: push hl push de push bc push af ld e,a ld c,_Conout call BDOS ; .. print pop af pop bc pop de pop hl ret ; ; Get number from input ; EXIT Zero set if no number ; Reg HL holds number ; GetNum: push bc call ChrGet ; Get valid character bit _NM,b ; Test number jr z,GN.hex ; .. nope call GetDec jr GN.ex GN.hex: bit _EX,b ; Test hex prefix jr z,GN.ex ; .. nope call GetHex ; .. get it GN.ex: pop bc ret ; ; Get decimal number ; EXIT Reg HL holds number ; GetDec: push de push bc call ChrGet ; Get valid character bit _NM,b ; Test number jr z,GD.ex ; .. no ld hl,0 ; Init result jr GD.go GD.loop: ld e,l ; Copy number ld d,h add hl,hl ; * 2 add hl,hl ; * 4 add hl,de ; * 5 add hl,hl ; * 10 GD.go: ld a,c sub '0' ; Strip off offset add a,l ld l,a ; .. add to old number adc a,h sub l ld h,a call Get ; Get character from file call GetChr ; .. and attribute bit _NM,b ; Test still number jr nz,GD.loop ; .. yeap or 1 ; .. set success GD.ex: pop bc pop de ret ; ; Get hex number ; EXIT Reg HL holds number ; GetHex: push bc call ChrGet ; Get valid character bit _EX,b ; Test expansion prefix jr z,GH.ex ; .. nope call Get ; Get character from file call GetChr ; .. and attribute bit _HX,b ; Test hex call z,UnGet ; Unget character if not jr z,GH.ex ; .. and exit ld hl,0 ; Init result jr GH.go GH.loop: add hl,hl ; * 2 add hl,hl ; * 4 add hl,hl ; * 8 add hl,hl ; * 16 GH.go: ld a,c ; Get character and LoMask ; Mask lower part bit _NM,b ; Test 0..9 jr nz,GH.dec ; .. yeap add a,9 ; Fix for hex GH.dec: or l ld l,a ; Put into result call Get ; Get character from file call GetChr ; .. and attribute bit _HX,b ; Test still hex jr nz,GH.loop ; .. yeap or 1 ; Set success GH.ex: pop bc ret ; ; Get valid definition character from file ; ChrGet: jr .ChrGet ; .. skip reading from file CG.loop: call Get ; Get character from file .ChrGet: call GetChr ; Get character and attribute bit _EO,b ; Test end of file or line ret nz ; .. exit bit _IG,b ; Test valid character jr nz,CG.loop ; .. nope ret ; ; Prepare CCP command line ; EXIT Carry set if line OK ; PrepCCPLine: push hl push de push bc ld hl,CCPcmd ld a,(hl) ; Fetch length of input inc a ld (RecPtr),a ; .. save it inc hl ld (BufPtr),hl ; Init buffer dec a add a,l ; Point to end of line ld l,a adc a,h sub l ld h,a ld (hl),eof ; Close line scf pop bc pop de pop hl ret nc ; ; Get character from command line ; Store character and attribute ; Get: push hl push de push bc push af ld hl,(BufPtr) ; Get current pointer ld c,(hl) ; .. get character ex de,hl call PutChr ; .. save it ld a,c cp eof ; Test end of line jr z,Get.eof ld a,(RecPtr) dec a ; Fix pointers ld (RecPtr),a ex de,hl inc hl ld (BufPtr),hl Get.eof: pop af pop bc pop de pop hl ret ; ; Unget current character ; UnGet: push hl push de push bc push af ld a,(Char) ; Get character cp eof ; Test end of line ld hl,(BufPtr) jr z,UG.dummy ; .. yeap, skip ld hl,RecPtr inc (hl) ; Fix pointers if not ld hl,(BufPtr) dec hl ld (BufPtr),hl UG.dummy: dec hl ld c,(hl) call PutChr ; Save character and attribute pop af pop bc pop de pop hl ret ; ; Put character and attribute into memory ; ENTRY Reg C holds character ; PutChr: bit MSB,c ; Test 80..FF ld b,01h jr nz,.PutChr ; .. yeap, set standard ld b,0 ld hl,AttrTable add hl,bc ld b,(hl) ; Fetch attribute .PutChr: ld (Char),bc ; Save character and attribute ret ; ; Get current character and attribute ; EXIT Reg C holds character ; Reg B holds attribute ; GetChr: ld bc,(Char) ; Get character and attribute ret ; ; Get EOL or EOF state of current character ; EXIT Zero set if not EOL or EOF ; GetAttr: ld a,(Attr) ; Get attribute and 1 SHL _EO ; .. test bit ret ; ; Get version of machine ; EXIT Reg C holds type of machine ; 0 : CPC6128 ; 1 : PCW8256 ; 3 : CP/M 2.2 version ; 4 : Other machine ; GetVersion: ld c,_vers call BDOS ; Get OS version cp CPM31 ; Test CP/M+ jr z,Vers31 cp CPM22 ; Test CP/M 2.2 ld c,4 ret nz ld c,3 ret Vers31: ld hl,(OS+1) ld de,3*(_Userf-1) add hl,de ld (Userf+1),hl ; Set USERF vector call GetType ; Get machine type ld c,a ; .. set result ret ; ; Execute BIOS function 30 : USERF ; Userf: jp $-$ ; ; Get type of machine ; EXIT Accu holds type of machine ; GetType: call Userf ; .. get type dw CD.VERS ret ; ; Attribute table of all ASCII characters ; Bit definitions: ; ; 7 6 5 4 3 2 1 0 ; +----+----+----+----+----+----+----+----+ ; | xx | xx | EO | EX | NM | HX | AN | IG | ; +----+----+----+----+----+----+----+----+ ; ; xx N.C. ; EO EOL or EOF ; EX Extension string ; NM Numeric 0..9 ; HX Hex range A..F ; AN Alphanumeric prefix ; IG Ignore for definition ; AttrTable: ; ; Control characters ; db 01h,01h,01h,01h,01h,01h,01h ; 00..06 db 01h,01h,01h,01h,01h,01h,21h ; 07..0D db 01h,01h,01h,01h,01h,01h,01h ; 0E..14 db 01h,01h,01h,01h,01h,21h,01h ; 15..1B db 01h,01h,01h,01h ; 1C..1F ; ; ASCII characters ; db 01h,01h,00h,10h,01h,01h,10h ; !"#$%& db 01h,01h,01h,01h,01h,01h,01h ; '()*+,\ db 00h,01h,0ch,0ch,0ch,0ch,0ch ; ./01234 db 0ch,0ch,0ch,0ch,0ch,01h,01h ; 56789:; db 01h,01h,01h,01h,01h,06h,06h ; <=>?@AB db 06h,06h,06h,06h,02h,02h,02h ; CDEFGHI db 02h,02h,02h,02h,02h,02h,02h ; JKLMNOP db 02h,02h,02h,02h,02h,02h,02h ; QRSTUVW db 02h,02h,02h,01h,01h,01h,01h ; XYZ[\]^ db 01h,01h,06h,06h,06h,06h,06h ; _`abcde db 06h,02h,02h,02h,02h,02h,02h ; fghijkl db 02h,02h,02h,02h,02h,02h,02h ; mnopqrs db 02h,02h,02h,02h,02h,02h,02h ; tuvwxyz db 01h,01h,01h,01h,01h ; {|}~DEL db eof ds 246,0 DATA equ 1000h UsrStk equ DATA+256 LocStk equ UsrStk+258 BufPtr equ UsrStk+258 RecPtr equ BufPtr+2 Char equ RecPtr+1 Attr equ Char+1 end