;............................................................... ; ; FILE : UPRO3.S - protection - ; ------- ;............................................................... *============= * * DATE: MOD *------- ----- * 10/05/86 - STARTED PROJECT * 10/16/86 - ADDED APPLE 3.5 GS CODE * 10/21/86 - ADDED PARMS FOR HLSPRO * 10/26/86 - CORRECTED FOR BUGS IN GS * ADDED 65C816 OPCODES * *============= HLSCODE START Using GlobalData BNK0_ADDRESS GEQU $008000 CODE GEQU $000500 MAXLEN EQU $800 SIGBYT EQU $E6 MARK1 EQU $D5 MARK2 EQU $AA MARK3 EQU $96 * * PARMETER OFFSETS * ID_OFF EQU 0 ; HLSVOL EQU 0 ;Long address of signature string HLSTRK EQU 4 ;Signature track HLSID EQU 5 ; " sector * * TAG FIELD DEFINITION (HOW TO IDENTIFY THE SIGNATURE DISK) * SIGBLK EQU 2 ;Volume block TAGOFF EQU 5 ;Offset to volume name * * APPLE-ZPG VARIABLES * ZPG EQU $E0 PARM EQU $E0 PARMH EQU $E1 B0_HNDL EQU $E2 BNK0 EQU $E6 SLT EQU $EA UNIT EQU $EB MAXUNIT EQU $EC * * LIRON-ZPG VARIABLES * ADRL EQU $ED ;3 LATCH EQU $F0 ;2 MARK EQU $F2 ;2 BUFL EQU $F4 ;1 BUFH EQU $F5 LTEMP EQU $F6 COUNT EQU $F8 * * * LIRON-ZPG EQUATES * CURCYL EQU $0D CURDRIVE EQU $0F DRIVE EQU $13 CYL EQU $14 SIDE EQU $16 CURNSECT EQU $1A ADDRSUM EQU $27 ADDRFMT EQU $28 ADDRSID EQU $29 ADDRSEC EQU $2A ADDRTRK EQU $2B CMDTAB EQU $4C CMDPCOUNT EQU $4D CMDREMAIN EQU $4E BLKLO EQU $50 BLKMED EQU $51 BLKHI EQU $52 STATTAB EQU $56 STATBYTE EQU $57 FORMERR EQU $5E INTERLEAVE EQU $62 FORMSIDES EQU $63 READADDR EQU $72 READDATA EQU $75 WRITEDATA EQU $78 SEEK EQU $7B FORMAT EQU $7E WRITETRACK EQU $81 VERIFY EQU $84 VECTOR EQU $87 DATAMRK EQU $8E SYNCFLD EQU $91 BITSLIP EQU $97 ADDRMRK EQU $9F * * IWM CHIP OFFSETS * PH0L EQU $0 PH0H EQU $1 PH1L EQU $2 PH1H EQU $3 PH2L EQU $4 PH2H EQU $5 PH3L EQU $6 PH3H EQU $7 MTRON EQU $8 MTROFF EQU $9 ENABL1 EQU $A ENABL2 EQU $B Q6L EQU $C Q6H EQU $D Q7L EQU $E Q7H EQU $F LIRIWM EQU $A00 APLIWM EQU $C0E0 * * SMARTPORT-CONROL COMMANDS * EJECT EQU 1 ;LIRON 3.5 CONTROL CMDS CALL EQU 5 SETADR EQU 6 UPLOAD EQU 7 ; SETHOOK EQU 5 ;APPLE 3.5 (GS DRIVER) REHOOK EQU 6 SETMARK EQU 7 REMARK EQU 8 SETSIDE EQU 9 SETINTR EQU 10 NOCALL EQU $80 ALL_HOOKS EQU 0 RDAT_HOOK EQU 2 ; ST_STAT EQU 0 ;STATUS $03 OFFSETS DISKIN EQU $10 ST_SIZ EQU 1 ST_LEN EQU 4 ST_NAM EQU 5 ST_TYP EQU 21 UNITYP EQU 1 ST_SUB EQU 22 UNISUB EQU $00 APLSUB EQU $C0 ST_VER EQU 23 ; ST_ERR EQU 1 ;LIRON STATUS $05 OFF ST_TRY EQU 2 ST_A EQU 3 ST_X EQU 4 ST_Y EQU 5 ST_P EQU 6 65816 ON LONGA ON LONGI ON ******* * * HLSOPEN - START OF CODE * *FORMAT: * ERROR = HLSOPEN( PROGRAM_ID_NUMBER); * * *MEMORY MAP: * * X + 0000:BLOCK BUFFER * 0120:MY DIRECT PAGE(ZPG) BASE (ALL MY REFS ARE TO $E0 OR HIGHER) * 0200: MY REAL ZPG * 0220:THE BANK 0 PROTECTION CODE * ZPG_OFF EQU $200-ZPG CODE_OFF EQU $0220 LOCK EQU $8000 FIX EQU $4000 CROSS EQU $0010 SPCL EQU $0008 PGALGN EQU $0004 FIXADR EQU $0002 FIXBNK EQU $0001 * HLSOPEN ENTRY PHP PHD PHB PHK PLB REP #$30 LDA ID_OFF+3+2+1+1+1,S ;Get our ID STA OUR_ID JSR GET_MEM BCS QUIT JSR INSTALL LDA #$0000 ;No error CLC QUIT ENTRY PLB PLD ROL CARRY ;PRESERVE THE CARRY PLP ROR CARRY RTL * * GET_MEM - Allocate the necessary memory for the protection * GET_MEM ANOP ;-------------------------------------- ; pushlong #0 ; room for handle ; pushlong #$220+ENDPRO-KLUDGE ; Length of context routine ; LDA OUR_ID ; Our user ID ; PHA ; pushword #LOCK+FIX+CROSS+FIXBNK+FIXADR ; pushlong #BNK0_ADDRESS-CODE_OFF ; _NewHandle ;-------------------------------------- PushLong >Hdl_Upro3 |adresse bank 0 clc ;-- PLA STA TEMP PLA STA TEMP+2 BCC GOTMEM LDA #$34 BRA DONE GOTMEM ANOP JSR GET_OUR_PG0 LDA TEMP LDY TEMP+2 STA B0_HNDL STY B0_HNDL+2 LDA [B0_HNDL] LDY #$0000 STA SA_CMD JSR CONTROL BCS FAIL0 LDA #UPLOAD ;UPLOAD OUR TEST CODE LDX #LIRON JSR CONTROL BCS FAIL0 LDA #CALL ;CALL THE UPLOADED ROUTINE LDX #CA_CMD JSR CONTROL BCS FAIL0 LDA #$05 ;LIRON CTRL CALL FOR GET REGS JSR STATUS BCC GETREGS FAIL0 STA LST_ERR FAIL SEC RTS * * APLTST - CHECK APPLE 3.5 DRIVE * APLTST anop LDA #SETHOOK LDX #SH_CMD ;(HAR, HAR ME MATEYS) JSR CONTROL BCS FAIL0 JSR GETBLK JSR RBLK LDA #REHOOK LDX #RH_CMD JSR CONTROL BCS FAIL0 * GETREGS LDA ST_BUF+ST_P PHA LDA ST_BUF+ST_A LDX ST_BUF+ST_X LDY ST_BUF+ST_Y PLP SEP #$30 CLI BCS FAIL0 RTS * * CHKHLS - MAKE SURE DISK WAS MADE BY HLS * (ie. Our volume name or whatever is in the right block) * CHKHLS anop REP #$20 LONGA ON LDA [B0_HNDL] ;Buffer address STA BUFL STA RB_BUF LDY #HLSVOL ;VOLUME NAME OFFSET LDA (PARM),Y SEC SBC #TAGOFF ;TAGOFF is the offset into the block STA ADRL ; where we will find our string SEP #$20 LONGA OFF INY INY LDA (PARM),Y ;Get the bank byte SBC #^TAGOFF STA ADRL+2 ; LDX #SIGBLK ; (USUALLY THE VOLUME NAME) JSR RBLK BCS FAIL1 LDY #TAGOFF-1 CMPVOL INY LDA [OUR_PG0 ;Zpg=Our Zpg TCD SEP #$20 LDA >Y_REG STA COUNT LDA #APLIWM+Q6L JSR SETLAT PHB PHK PLB PHP STA ST_BUF+ST_A STX ST_BUF+ST_X STY ST_BUF+ST_Y PLA STA ST_BUF+ST_P PLB PLD CLC RTL ****** * * STATUS - SMARTPORT STATUS CALL * STATUS anop ;-- STA ST_COD LDA UNIT STA ST_UNIT LDA #$00 JSR CALL_IT ST_CMD dc H'03' ST_UNIT dc H'01' DC A2'ST_BUF' ST_COD dc H'00' ST_BUF DS 28 * * RBLK - Read a block * RBLK anop STX RB_BLK STY RB_BLK+1 LDA #$01 JSR CALL_IT RB_CMD dc H'03' RB_UNIT dc H'01' RB_BUF DC A2'$2000' RB_BLK DC I4'$0000' * * CONTROL - * CONTROL anop STA CT_SUB STX CT_BUF STY CT_BUF+1 LDA #$04 JSR CALL_IT CT_CMD dc H'03' CT_UNIT dc H'01' CT_BUF DC A2'CA_CMD' CT_SUB dc H'00' * CA_CMD DC I2'0006' A_REG dc H'00' X_REG dc H'00' Y_REG dc H'00' P_REG dc H'34' CA_ADR DC A'CODE' * SA_CMD DC I2'0002' DC A'CODE' * SH_CMD DC I2'0004' dc i1' NOCALL+RDAT_HOOK ' DC A4'MY_RDAT' * RH_CMD DC I2'0004' dc i1' ALL_HOOKS ' * CALL_IT STA DISPATCH+3 REP #$20 PLA ;Pull the address of the parameters INC A ; (Just after the call) STA DISPATCH+4 SEP #$30 JSL DISPAT0 RTS EMULSTACK EQU $010100 ;Bank $01/ Page $01 DISPAT0 PHD PHB ;Save the world PHP REP #$30 LONGA ON LONGI ON TSC TSX SEP #$20 LONGA OFF XBA ;Set the stack somewhere in DEC A ; $01/$01xx like emulation will do BEQ ALREADY_PG1 ; (unless it already is!!) LDA #>$100 XBA LDA >EMULSTACK SEC SBC #$10 TCS ;Set 6502 SP ALREADY_PG1 ANOP PEA $0000 PLD ;Direct page = $0000 LDA #>$00 PHA PLB ;Data Bank = $00 PHX ;Save native SP SEC XCE ;6502 Emulation=ON 65C02 ON ; DISPATCH JSR $FFFF DIS_OFF EQU *-DISPAT0 DC H'00' DC A2' ST_CMD' ; PHP CLC XCE ;Native 65816 mode 65816 ON PLP TAY ROR A REP #$10 ;(long x) LONGI ON PLX TXS PLP ;Status LONGI OFF PLB ;Data Bank PLD ;Direct Page Reg ROL A ;Recover the carry/error TYA RTL ;PC & Program Bank * * GET_SMART - FIND THE SMARTCARD * GET_SMART anop TXA LDX #<$E1C000 ORA #>$E1C000 STX LIRIWM+Q6L BNE SETLAT SKERR LDA #$32 dc H'2C' SKERR1 LDA #$31 dc H'2C' LFAIL LDA #$30 SEC RTS SETLAT anop CNTOFF EQU SETLAT-LIRON STA LATCH STY LATCH+1 LDA #$00 STA BUFL STA BUFH CNTADR anop LDX #<$0000-MAXLEN LDY #>$0000-MAXLEN STY LTEMP+1 TSL0 INX BNE TSL1 INC LTEMP+1 BEQ LFAIL TSL1 LDA (LATCH) BPL TSL1 TSL2 CMP #MARK1 BNE TSL0 TSL3 LDA (LATCH) BPL TSL3 CMP #MARK2 BNE TSL2 TSL4 LDA (LATCH) BPL TSL4 CMP #MARK3 BNE TSL2 CLC TXA ADC #MAXLEN+3+2 TAY CLC TXA ADC BUFL STA BUFL TYA ADC BUFH STA BUFH DEC COUNT BNE CNTADR LDA #$00 LDX BUFL LDY BUFH CLC RTS OBJEND * * ENDPRO - END OF UNMODIFIED CODE * ENDPRO anop END