[comp.binaries.apple2] PIDGIN.MAC

tm@polari.UUCP (Toshi Morita) (07/24/90)

U:;$^ 

;
; Pidgin macro set (6502) for Merlin Pro/ProDOS
;
; by Toshiyasu Morita
;
; Started: 9/1/88 @ 9:49 am
;

;
; Header macros & other misc macros
;

:top;

        @ LST OFF;
        @ ORG $2000;
        @ JMP _beginmain:;
        @ PUT PIDGIN.RT;

:top.gs;

        @ LST OFF;
        @ ORG $2000;
        @ JMP _beginmain:;
        @ PUT PIDGIN.GS.RT;

:bottom;
        @_progend:;
        @ TYP $FF;
        @ SAV TEST;

:beginmain(AC,IAV);

        @ LST ON;
        _beginmain:;
        @ LST OFF;
        @ CLD;

:endmain;

        @ RTS;

:const K$$=+$$$;

        _K^P1C^P2C EQU ^V3S^V4*^V5*^!0N;

:ascii '$$$$$$$$$';

        ASC '^P1C^P2C^P3C^P4C^P5C^P6C^P7C^P8C^P9C';

:null;

        HEX 00;

;
; Basic datatype definition macros
;

:byte $$;

        _^P1C^P2C: DS 1;

:int I$$;

        _I^P1C^P2C: DS 2;

:byte $$($$$);

        _^P1C^P2C: DS ^V3S^V4*^V5*^!0N;

:int I$$($$$);

        _I^P1C^P2C: DS 2*^V3S^V4*^V5*^!0N;

:byte $$($$$$$);

        _^P1C^P2C: DS ^V3S^V4*^V5*^V6*^V7*^!0N;

;
; Set variables to constants macros
;

:$$='$';

        @ LDA #'^P3C';
        @ STA _^P1C^P2C:;

:$$=K$$;

        @ LDA #_K^P3C^P4C;
        @ STA _^P1C^P2C:;

:$$=+$$$;

        @ LDA #^V3S^V4*^V5*^!0N;
        @ STA _^P1C^P2C:;

:I$$=+00000;    Special-case macro to generate shorter code

        @ LDA #0;
        @ STA _I^P1C^P2C:;
        @ STA _I^P1C^P2C:+1;

:I$$=+$$$$$;

        @ LDA #<^V3S^V4*^V5*^V6*^V7*^!0N;
        @ STA _I^P1C^P2C:;
        @ LDA #>^V3S^V4*^V5*^V6*^V7*^!0N;
        @ STA _I^P1C^P2C:+1;

:I$$=heap;

        @ LDA #<_progend:;
        @ STA _I^P1C^P2C:;
        @ LDA #>_progend:;
        @ STA _I^P1C^P2C:;

;
; Data conversion macros
;

:$$=$$;

        @ LDA _^P3C^P4C:;
        @ STA _^P1C^P2C:;

:I$$=I$$;

        @ LDA _I^P3C^P4C:;
        @ STA _I^P1C^P2C:;
        @ LDA _I^P3C^P4C:+1;
        @ STA _I^P1C^P2C:+1;

:I$$=$$;

        @ LDA _^P3C^P4C:;
        @ STA _I^P1C^P2C:;
        @ LDA #0;
        @ STA _I^P1C^P2C:+1;

:$$=I$$;

        @ LDA _I^P3C^P4C:;
        @ STA _^P1C^P2C:;

:pack(I$$,$$,$$);

        @ LDA _^P5C^P6C:;
        @ STA _I^P1C^P2C:;
        @ LDA _^P3C^P4C:;
        @ STA _I^P1C^P2C:+1;

:unpack(I$$,$$,$$);

        @ LDA _I^P1C^P2C:;
        @ STA _^P3C^P4C:;
        @ LDA _I^P1C^P2C:+1;
        @ STA _^P5C^P6C:;

;
; Array operations
;

:$$=$$($$);

        @ LDY _^P5C^P6C:;
        @ LDA _^P3C^P4C:,Y;
        @ STA _^P1C^P2C:;

:$$($$)=$$;

        @ LDA _^P5C^P6C:;
        @ LDY _^P3C^P4C:;
        @ STA _^P1C^P2C:,Y;

:$$($$)=+$$$;

        @ LDA #^V5S^V6*^V7*^!0N;
        @ LDY _^P3C^P4C:;
        @ STA _^P1C^P2C:,Y;

:$$($$)=K$$;

        @ LDA #_K^P5C^P6C;
        @ LDY _^P3C^P4C:;
        @ STA _^P1C^P2C:,Y;

:$$($$)='$';

        @ LDA #'^P5C';
        @ LDY _^P3C^P4C:;
        @ STA _^P1C^P2C:,Y;

:$$=$$(I$$);    Macro OK

        @ LDA #<_^P3C^P4C:;
        @ CLC;
        @ ADC _I^P5C^P6C:;
        @ STA PNTR;
        @ LDA #>_^P3C^P4C:;
        @ ADC _I^P5C^P6C:+1;
        @ STA PNTR+1;
        @ LDY #0;
        @ LDA (PNTR),Y;
        @ STA _^P1C^P2C:;

:$$(I$$)=$$;

        @ LDA #<_^P1C^P2C:;
        @ CLC;
        @ ADC _I^P3C^P4C:;
        @ STA PNTR;
        @ LDA #>_^P1C^P2C:;
        @ ADC _I^P3C^P4C:+1;
        @ STA PNTR+1;
        @ LDA _^P5C^P6C:;
        @ LDY #0;
        @ STA (PNTR),Y;

:$$(I$$)=+$$$;

        @ LDA #<_^P1C^P2C:;
        @ CLC;
        @ ADC _I^P3C^P4C:;
        @ STA PNTR;
        @ LDA #>_^P1C^P2C:;
        @ ADC _I^P3C^P4C:+1;
        @ STA PNTR+1;
        @ LDA #^V5S^V6*^V7*^!0N;
        @ LDY #0;
        @ STA (PNTR),Y;

:$$(I$$)=K$$;

        @ LDA #<_^P1C^P2C:;
        @ CLC;
        @ ADC _I^P3C^P4C:;
        @ STA PNTR;
        @ LDA #>_^P1C^P2C:;
        @ ADC _I^P3C^P4C:+1;
        @ STA PNTR+1;
        @ LDA #_K^P5C^P6C;
        @ LDY #0;
        @ STA (PNTR),Y;

:$$(I$$)='$';

        @ LDA #<_^P1C^P2C:;
        @ CLC;
        @ ADC _I^P3C^P4C:;
        @ STA PNTR;
        @ LDA #>_^P1C^P2C:;
        @ ADC _I^P3C^P4C:+1;
        @ STA PNTR+1;
        @ LDA #'^P5C';
        @ LDY #0;
        @ STA (PNTR),Y;

:I$$=I$$($$);

        @ LDA _^P5C^P6C:;
        @ ASL;
        @ TAY;
        @ LDA _I^P3C^P4C:,Y;
        @ STA _I^P1C^P2C:;
        @ LDA _I^P3C^P4C:+1,Y;
        @ STA _I^P1C^P2C:+1;

:I$$($$)=I$$;

        @ LDX #0;
        @ LDA _^P3C^P4C:;
        @ ASL;
        @ BCC *+3;
        @ INX;
        @ CLC;
        @ ADC #<_I^P1C^P2C:;
        @ STA PNTR;
        @ TXA;
        @ ADC #>_I^P1C^P2C:+1;
        @ STA PNTR+1;
        @ LDA _I^P5C^P6C:;
        @ LDY #0;
        @ STA (PNTR),Y;
        @ LDA _I^P5C^P6C:+1;
        @ INY;
        @ STA (PNTR),Y;

:I$$=I$$(I$$);

        @ LDA #<_I^P3C^P4C:;
        @ CLC;
        @ ADC _I^P5C^P6C:;
        @ STA PNTR;
        @ LDA #>_I^P3C^P4C:;
        @ ADC _I^P5C^P6C:+1;
        @ STA PNTR+1;
        @ LDY #0;
        @ LDA (PNTR),Y;
        @ STA _I^P1C^P2C:;
        @ INY;
        @ LDA (PNTR),Y;
        @ STA _I^P1C^P2C:+1;

:I$$(I$$)=I$$;

        @ LDA #<_I^P1C^P2C:;
        @ CLC;
        @ ADC _I^P3C^P4C:;
        @ STA PNTR;
        @ LDA #>_I^P1C^P2C:;
        @ ADC _I^P3C^P4C:+1;
        @ STA PNTR+1;
        @ LDY #0;
        @ LDA _I^P5C^P6C:;
        @ STA (PNTR),Y;
        @ INY;
        @ LDA _I^P5C^P6C:+1;
        @ STA (PNTR),Y;

;
; Heap operations
;

:$$=(I$$);

        @ LDA _I^P3C^P4C:;
        @ STA PNTR;
        @ LDA _I^P3C^P4C:+1;
        @ STA PNTR+1;
        @ LDX #0;
        @ LDA (PNTR,X);
        @ STA _^P1C^P2C:;

:(I$$)=$$;

        @ LDA _I^P1C^P2C:;
        @ STA PNTR;
        @ LDA _I^P1C^P2C:+1;
        @ STA PNTR+1;
        @ LDA _^P3C^P4C:;
        @ LDX #0;
        @ STA (PNTR,X);

:(I$$)='$';

        @ LDA _I^P1C^P2C:;
        @ STA PNTR;
        @ LDA _I^P1C^P2C:+1;
        @ STA PNTR+1;
        @ LDA #'^P3C';
        @ LDX #0;
        @ STA (PNTR,X);

:(I$$)=K$$;

        @ LDA _I^P1C^P2C:;
        @ STA PNTR;
        @ LDA _I^P1C^P2C:+1;
        @ STA PNTR+1;
        @ LDA #_K^P3C^P4C;
        @ LDX #0;
        @ STA (PNTR,X);

:(I$$)=+$$$;

        @ LDA _I^P1C^P2C:;
        @ STA PNTR;
        @ LDA _I^P1C^P2C:+1;
        @ STA PNTR+1;
        @ LDA #^V3S^V4*^V5*^!0N;
        @ LDX #0;
        @ STA (PNTR,X);

:I$$=(I$$);

        @ LDA _I^P3C^P4C:;
        @ STA PNTR;
        @ LDA _I^P3C^P4C:+1;
        @ STA PNTR+1;
        @ LDY #0;
        @ LDA (PNTR),Y;
        @ STA _I^P1C^P2C:;
        @ INY;
        @ LDA (PNTR),Y;
        @ STA _I^P1C^P2C:+1;

:(I$$)=I$$;

        @ LDA _I^P1C^P2C:;
        @ STA PNTR;
        @ LDA _I^P1C^P2C:+1;
        @ STA PNTR+1;
        @ LDY #0;
        @ LDA _I^P3C^P4C:;
        @ STA (PNTR),Y;
        @ INY;
        @ LDA _I^P3C^P4C:+1;
        @ STA (PNTR),Y;

;
; Arithmetic operations
;

:$$=$$+$$;

        @ LDA _^P3C^P4C:;
        @ CLC;
        @ ADC _^P5C^P6C:;
        @ STA _^P1C^P2C:;

:$$=$$-$$;

        @ LDA _^P3C^P4C:;
        @ SEC;
        @ SBC _^P5C^P6C:;
        @ STA _^P1C^P2C:;

:$$=$$&$$;

        @ LDA _^P3C^P4C:;
        @ AND _^P5C^P6C:;
        @ STA _^P1C^P2C:;

:$$=$$?$$;

        @ LDA _^P3C^P4C:;
        @ ORA _^P5C^P6C:;
        @ STA _^P1C^P2C:;

:$$=$$%$$;

        @ LDA _^P3C^P4C:;
        @ ORA _^P5C^P6C:;
        @ STA _^P1C^P2C:;

:I$$=-I$$;

        @ LDA #0;
        @ SEC;
        @ SBC _I^P3C^P4C:;
        @ STA _I^P1C^P2C:;
        @ LDA #0;
        @ SBC _I^P3C^P4C:+1;
        @ STA _I^P1C^P2C:+1;

:I$$=I$$+$$;

        @ LDA _I^P3C^P4C:;
        @ CLC;
        @ ADC _^P5C^P6C:;
        @ STA _I^P1C^P2C:;
        @ LDA _I^P3C^P4C:+1;
        @ ADC #0;
        @ STA _I^P1C^P2C:+1;

:I$$=I$$+I$$;

        @ LDA _I^P3C^P4C:;
        @ CLC;
        @ ADC _I^P5C^P6C:;
        @ STA _I^P1C^P2C:;
        @ LDA _I^P3C^P4C:+1;
        @ ADC _I^P5C^P6C:+1;
        @ STA _I^P1C^P2C:+1;

:I$$=I$$-$$;

        @ LDA _I^P3C^P4C:;
        @ SEC;
        @ SBC _^P5C^P6C:;
        @ STA _I^P1C^P2C:;
        @ LDA _I^P3C^P4C:+1;
        @ SBC #0;
        @ STA _I^P1C^P2C:+1;

:I$$=I$$-I$$;

        @ LDA _I^P3C^P4C:;
        @ SEC;
        @ SBC _I^P5C^P6C:;
        @ STA _I^P1C^P2C:;
        @ LDA _I^P3C^P4C:+1;
        @ SBC _I^P5C^P6C:+1;
        @ STA _I^P1C^P2C:+1;

;I$$=I$$*I$$;

:I$$=I$$/I$$;

;
; Comparison operators
;

:$$!=$$;

        @ LDA _^P3C^P4C:;
        @ EOR #$FF;
        @ STA _^P1C^P2C:;

:$$=$$==$$;

        @ LDX #$FF;
        @ LDA _^P3C^P4C:;
        @ CMP _^P5C^P6C:;
        @ BEQ *+3;
        @ INX;
        @ STX _^P1C^P2C:;

:$$=$$!=$$;

        @ LDX #$FF;
        @ LDA _^P3C^P4C:;
        @ CMP _^P5C^P6C:;
        @ BNE *+3;
        @ INX;
        @ STX _^P1C^P2C:;

:$$=$$<=$$;     Macro OK

        @ LDX #$FF;
        @ LDA _^P3C^P4C:;
        @ CMP _^P5C^P6C:;
        @ BCC *+3;
        @ INX;
        @ STX _^P1C^P2C:;

:$$=$$<!$$;

        @ LDX #$FF;
        @ LDA _^P3C^P4C:;
        @ CMP _^P5C^P6C:;
        @ BEQ *+5;
        @ BCC *+3;
        @ INX;
        @ STX _^P1C^P2C:;

:$$=$$==K$$;

        @ LDX #$FF;
        @ LDA _^P3C^P4C:;
        @ CMP #_K^P5C^P6C;
        @ BEQ *+3;
        @ INX;
        @ STX _^P1C^P2C:;

:$$=$$!=K$$;

        @ LDX #$FF;
        @ LDA _^P3C^P4C:;
        @ CMP #_K^P5C^P6C;
        @ BNE *+3;
        @ INX;
        @ STX _^P1C^P2C:;

:$$=$$<=K$$;

        @ LDX #$FF;
        @ LDA _^P3C^P4C:;
        @ CMP #_K^P5C^P6C;
        @ BCC *+5;
        @ BEQ *+3;
        @ INX;
        @ STX _^P1C^P2C:;

:$$=$$<!K$$;

        @ LDX #$FF;
        @ LDA _^P3C^P4C:;
        @ CMP #_K^P5C^P6C;
        @ BCC *+3;
        @ INX;
        @ STX _^P1C^P2C:;

:$$=I$$==I$$;

        @ LDX #$FF;
        @ LDA _I^P3C^P4C:;
        @ CMP _I^P5C^P6C:;
        @ BNE *+10;
        @ LDA _I^P3C^P4C:+1;
        @ CMP _I^P5C^P6C:+1;
        @ BEQ *+3;
        @ INX;
        @ STX _^P1C^P2C:;

:$$=I$$!=I$$;

        @ LDX #$FF;
        @ LDA _I^P3C^P4C:;
        @ CMP _I^P5C^P6C:;
        @ BNE *+11;
        @ LDA _I^P3C^P4C:+1;
        @ CMP _I^P5C^P6C:+1;
        @ BNE *+3;
        @ INX;
        @ STX _^P1C^P2C:;

:$$=I$$<=I$$;   Macro OK

        @ LDX #$FF;
        @ LDA _I^P3C^P4C:+1;
        @ CMP _I^P5C^P6C:+1;
        @ BCC *+17;
        @ BEQ *+4;
        @ BCS *+12;
        @ LDA _I^P3C^P4C:;
        @ CMP _I^P5C^P6C:;
        @ BEQ *+5;
        @ BCC *+3;
        @ INX;
        @ STX _^P1C^P2C:;

:$$=I$$<!I$$;   Macro OK

        @ LDX #$FF;
        @ LDA _I^P3C^P4C:+1;
        @ CMP _I^P5C^P6C:+1;
        @ BCC *+15;
        @ BEQ *+4;
        @ BCS *+10;
        @ LDA _I^P3C^P4C:;
        @ CMP _I^P5C^P6C:;
        @ BCC *+3;
        @ INX;
        @ STX _^P1C^P2C:;

;
; C-like increment/decrement operators
;

:$$--;          Macro OK

        @ DEC _^P1C^P2C:;

:$$++;          Macro OK

        @ INC _^P1C^P2C:;

:I$$--;         Macro OK

        @ LDA _I^P1C^P2C:;
        @ BNE *+5;
        @ DEC _I^P1C^P2C:+1;
        @ DEC _I^P1C^P2C:;

:I$$++;         Macro OK

        @ INC _I^P1C^P2C:;
        @ BNE *+5;
        @ INC _I^P1C^P2C:+1;

;
; Conditionals
;

; (if-else-endif construct)

:if $$;

        @ LDA _^P1C^P2C:;
        @ BNE *+5;
        @ JMP _F^U0S^S0N:;

:else;

        @ JMP _F^U0P^P0N^!9P:;
        _F^P9N:;
        ^P0S

:endif;

        _F^!0N:;

; (choose on $$-case $$-default-endchoose construct)

:choose on $$;  Macro OK

        @ LDA _^P1C^P2C:;
        ^U0S^N3S^U1S;
        @ JMP *+6;

:case $$;       Macro OK

        ^!0P^!9P^!8P
        @ JMP _XC^P0N:;
        _UP^P8N: CMP _^P1C^P2C:;
        @ BEQ *+5;
        @ JMP _UP^U1S^S8N^N0S^P0S:;

:case K$$;

        ^!0P^!9P^!8P
        @ JMP _XC^P0N:;
        _UP^P8N: CMP #_K^P1C^P2C;
        @ BEQ *+5;
        @ JMP _UP^U1S^S8N^N0S^P0S:;

:case '$';

        ^!0P^!9P^!8P
        @ JMP _XC^P0N:;
        _UP^P8N: CMP #'^P1C';
        @ BEQ *+5;
        @ JMP _UP^U1S^S8N^N0S^P0S:;

:case +$$$;     Macro OK

        ^!0P^!9P^!8P
        @ JMP _XC^P0N:;
        _UP^P8N: CMP #^V1S^V2*^V3*^!0N;
        @ BEQ *+5;
        @ JMP _UP^U1S^S8N^N0S^P0S:;

:default;       Macro OK

        ^!0P^!9P^!8P
        @ JMP _XC^P0N:;
        _UP^P8N:;
        ^P0S

:endchoose;     Macro OK

        _XC^!0N@:;

; (while-on $$-endwhile construct)

:while;         Macro OK

        ^U0S_X^S0N:;

:on $$;         Macro OK

        @ LDA _^P1C^P2C:;
        @ BNE *+5;
        @ JMP _W^S0N:;

:endwhile;      Macro OK

        @ JMP _X^S0N:;
        _W^!0N:;

;
; Gotos & subroutines
;

:loc $$;

        __LLO^P1C^P2C:;

:loc $$$$$$$$$;

        __LLO^P1C^P2C^P3C^P4C^P5C^P6C^P7C^P8C^P9C:;

:sub $$;

        @ LST ON;
        __^P1C^P2C:;
        @ LST OFF;

:sub $$$$$$$$$;

        @ LST ON;
        __^P1C^P2C^P3C^P4C^P5C^P6C^P7C^P8C^P9C:;
        @ LST OFF;

:goto $$;

        @ JMP __LLO^P1C^P2C:;

:goto $$$$$$$$$;

        @ JMP __LLO^P1C^P2C^P3C^P4C^P5C^P6C^P7C^P8C^P9C:;

:gosub $$;

        @ JSR __^P1C^P2C:;

:gosub $$$$$$$$$;

        @ JSR __^P1C^P2C^P3C^P4C^P5C^P6C^P7C^P8C^P9C:;

:call I$$;

        @ LDA #>*+9;
        @ PHA;
        @ LDA #<*+6;
        @ PHA;
        @ JMP (_I^P1C^P2C:);

:endsub;

        @ RTS;

:return;

        @ RTS;

;
; I/O subroutines
;

:decprt I$$;    Macro OK

        @ LDY _I^P1C^P2C:;
        @ LDX _I^P1C^P2C:+1;
        @ JSR __PRTDEC;

:read $$;

        @ JSR __GETKEY;
        @ STA _^P1C^P2C:;

:write $$;

        @ LDA _^P1C^P2C:;
        @ JSR __COUT;

:write K$$;

        @ LDA #_K^P1C^P2C;
        @ JSR __COUT;

:write '$';

        @ LDA #'^P1C';
        @ JSR __COUT;

:ms '$$$$$$$$$';

        @ JSR __MSG;
        @ ASC "^P1C^P2C^P3C^P4C^P5C^P6C^P7C^P8C^P9C";
        @ BRK;

:curpos($$,$$);

        @ LDA _^P1C^P2C:;
        @ STA CV;
        @ JSR BASCALC;
        @ LDA _^P3C^P4C:;
        @ STA CH;

:curpos(+$$$,+$$$);

        @ LDA #^V1S^V2*^V3*^!0N;
        @ STA CV;
        @ JSR BASCALC;
        @ LDA #^V4S^V5*^V6*^!0N;
        @ STA CH;

;
; File I/O subroutines
;

:I$$,I$$=file_len($);

        @ JSR __FLEN;
        @ DFB ^P5C;
        @ DW I_^P1C^P2C:,I_^P3C^P4C:;

:file_open($,$$);

        @ JSR __FOPEN;
        @ DFB ^P1C;
        @ DW _^P2C^P3C:;

:file_read($,$$,I$$);

        @ JSR __FREAD;
        @ DFB ^P1C;
        @ DW _^P2C^P3C:,_I^P4C^P5C:;

:file_close($);

        @ JSR __FCLOSE;
        @ DFB ^P1C;

;
; Serial I/O subroutines
;

:modem_init;

        @ JSR __MINIT;

:modem_read($$);

        @ JSR __MREAD;
        @ STA _^P1C^P2C:;

:modem_write($$);

        @ LDA _^P1C^P2C:;
        @ JSR __MWRITE;

:?modem_read($$);

        @ LDA #1;
        @ JSR __MREADY;
        @ STA _^P1C^P2C:;

:?modem_write($$);

        @ LDA #0;
        @ JSR __MREADY;
        @ STA _^P1C^P2C:;