Subject: Re: TransWarp GS - how to get/set speed?
From: [email-masked] (Greg DaCosta)
Date: Tue, 12 Oct 93 20:29:20 PDT
Newsgroups: comp.sys.apple2.programmer

Ian,

What follows is the Merlin source to an EXE file to control the speed of
the TWGS.  I wrote this about 4 years ago, so it doesn't know anything
about the Cache size.  I hope it helps.  

 lst off ;lose the playback!

*=========================================================================*
*                                                                         *
*  SPEED ...................................................... ver. 1.0  *
*                                                                         *
*    written by Greg A. DaCosta / copyright 1989, Desert Sun Software     *
*               GEnie: [G.DACOSTA]                                        *
*                                                                         *
* This program may be distributed freely as long as these credits remain  *
* intact and unmodified.                                                  *
*                                                                         *
* No fee may be charged for this program other than a minimal distri-     *
* bution fee (not to exceed $10). The only exception is distribution on   *
* the Merlin 16+ disk.                                                    *
*                                                                         *
*=========================================================================*
*                                                                         *
* This source code based on the DUMP command by Glen Bredon. It's not too *
* pretty, but it works well.  Thanks to Eric Mueller for his InstDA file  *
* which was a valuable aid in making this work.                           *
*                                                                         *
*=========================================================================*

        ttl     "SPEED"

        xc
        xc              ;Turn on full 65816 assembly
        mx %00

        cas in          ;case insensitive

         rel
        dsk 6/speed.l
        typ     exe

        tr
        tr      adr
        exp     off

*===============================

CSWH = $37

PNT = $60               ;Misc use
STACKPNT = $68

KEY = $E0C000
STROBE = $E0C010

SetSpeed = $BCFF2C      ;TWGS memory location
CheckTW = $BCFF00       ;ditto here

*===============================

Tool    MAC
        IF MX
        ERR 1
        ELSE
        LDX #]1
        JSL $E10000
         FIN
 <<<

WriteChr MAC
 Tool $180C
 <<<

print2 MAC
 JSR SENDMSG2
 ASC ]1,00
 <<<

PRINT MAC
 JSR SENDMSG
 ASC ]1,00
 mx %11 ;eight bit
 <<<

*-------------------------------------------------

*==============================
* Optional header on EXE files:
*------------------------------

START   BRL     Speed   ;Initialization entry
        BRL     Speed   ;Secondary entry
        BRL     Speed   ;Other required entry
        BRL     Speed   ; vectors, not used by Speed.
        BRL     Speed
        BRL     Speed
        BRL     Speed
        BRL     Speed

        DA      0       ;= ID of transient commands

        ASC     'MERLIN' ;= ID of special EXE file

*========================================
* End of optional structure for EXE file.
*----------------------------------------

Speed   PHK
        PLB

        TSC
        STA     STACKPNT

        TYA
        CLC
        ADC     #8      ;Bypass the "MERLINGS"
        STA     PNT     ; identifier - it is not
        TXA             ; checked for in this
        ADC     #0      ; example
        STA     PNT+2

        lda     #$8d
        jsr     OUTPUT
        jsr     RtnSpcs
        print   "SPEED shell command by Greg A. DaCosta"
        jsr     RtnSpcs
        print   "Copyright 1989, Desert Sun Software"

        SEP     %00110000
        LDY     #0
]LOOP   LDX     #0              ;Look for "SPEED" in order
        PHY                     ; to align index to the
]LUP    LDA     [PNT],Y         ; following part of cmd.
        BEQ     :EX             ;Something wrong if taken
        AND     #%01011111
        CMP     cmdWORD+1,X
        BEQ     :NX
        PLY
        INY
        BRA     ]LOOP

:NX     INX
        INY
        CPX     #5              ;all letters?
        BLT     ]LUP
        PLA                     ;Pop pushed Y
        DEY
]LUP    INY
        LDA     [PNT],Y
        AND     #$7F            ;Not needed
        BEQ     :EX             ;Nothing after "SPEED" so
        CMP     #'*'            ; do nothing.
        BLT     ]LUP            ;Bypass delimiter & spaces
        LDX     #0
]LUP    LDA     [PNT],Y
        AND     #$7F
        CMP     #$60
        BLT     :SB
        AND     #%01011111
:SB     STA     BUFFER,X
        BEQ     :GOTIT          ;Branch if no more input
        CMP     #'*'
        BEQ     :IX
        CMP     #'.'
        BLT     :GOTIT          ; or if excess input
:IX     INX
        INY
        BRA     ]LUP

:EX
        BRL     EXIT

        mx      %11             ;back to eight bit to store the filename

:GOTIT  STX     Speedname       ;Store length
        DEX
        BMI     :EX
:MOV    LDA     BUFFER,X
        STA     speedname+1,X   ;Save the speed which
        DEX                     ; the user wants installed.
        BPL     :MOV
        rep     #$30
        jsr     IsATwgs         ;Check to see if A TWGS is installed
        bcc     :NoTW
        sep     #$30            ;back to 8 bits for checking
        ldx     #0
        lda     BUFFER,x
        and     #$DF
        cmp     #'F'            ;Is it an "F"?
        beq     :fast
        cmp     #'S'            ;Is it an "S"?
        beq     :slow
        bra     :max            ;Otherwise just set the Max Speed

:NoTW   rep     #$30
        jsr     RtnSpcs
        print   "Sorry, a TWGS is not installed in this System."
        brl     EXIT

:slow   jsr     Slow
        brl     EXIT

:fast   jsr     Fast
        brl     EXIT

:max    jsr     Warp
        brl     EXIT

EXIT    SEP     %00110000
        LDAL    CSWH
        CMP     #$C3
        BNE     EXIT2           ;Exit if not screen output
        lda     #$8d
        jsr     OUTPUT
        jsr     RtnSpcs
        print   "Press RETURN."

]LUP    LDAL     KEY    ;Else wait for key
        BPL     ]LUP
        XBA
        LDAL    STROBE
        XBA
        CMP     #$8D
        BNE     ]LUP
EXIT2   print   8D8D
        rep     #$30
        LDA     STACKPNT
        TCS
        LDA     #0              ;No error
        RTL                     ;All done

        mx      %00

* print some spaces

RtnSpcs  rep    #$30
        lda     #$8d    ;print a return first
        jsr     OUTPUT
Spcs    ldx     #20
:loop   phx
        lda     #$a0
        jsr     OUTPUT
        plx
        dex
        bne     :loop
        rts

*===============================

SENDMSG2 REP    %00100001
        LDA     1,S
        INC
        STA     1,S
        SEP     %00110000
        LDY     #0
        LDA     (1,S),Y
        BEQ     :back
        JSR     OUTPUT
        BRA     SENDMSG2
:back   rep     #$30            ;back to full 16 bit
        rts

SENDMSG REP     %00100001
        LDA     1,S
        INC
        STA     1,S
        SEP     %00110000
        LDY     #0
        LDA     (1,S),Y
        BEQ     BACK
        JSR     OUTPUT
        BRA     SENDMSG

OUTPUT  PHA
        PHX
        PHY
        PHP
        REP     %00110000
        PHA
        WriteChr
        PLP
        PLY
        PLX
        PLA
BACK    RTS

*===============================

cmdWord str 'SPEED'

*===============================

IsATWgs mx      %00
        lda     >CheckTW                ;check Low word of ID
        cmp     #'TW'                   ;does it say TW?
        bne     :bad                    ;if not, get outta here
        lda     >CheckTW+2              ;check high word
        cmp     #'GS'
        beq     :rts
:bad    clc
:rts rts

Slow    mx      %00
        rep     $30
        php
        ldx     #0
        jsl     SetSpeed
        jmp     rts1

Fast    mx      %00
        php
        rep     $30
        ldx     #1
        jsl     SetSpeed
        jmp     rts1

Warp    mx      %00
        php
        rep     $30
        ldx     #2
        jsl     SetSpeed

rts1    plp
        rts

*===============================

BUFFER  DS      $80,$8D

Speedname ds    $80

     _   _
    / _ | \  Greg DaCosta, Sysop - Pro-Desert BBS 
    \_| |_/  Internet: [email-masked]