[Coco] Self-Patching LOADM (Was: CoCo3 MMU test for all)

Darren A. darccml at hotmail.com
Thu Jan 24 15:00:18 EST 2008


Roger,

Here is a neat self-patch trick you may want to consider. Since LOADM calls Console In to read each byte of the .bin file, you can insert the 3 segments described below to automatically fork to a custom loader during LOADM. This should work for any version of Disk Basic as long as LOADM has not been re-implemented to bypass Console In.

Segment 1:
Loaded at $1DA (Cassette Buffer)
A customized version of the LOADM code (see below) which reads the stream of pre(post)amble/data blocks from the bin file, but does NOT verify writes to memory.

Segment 2:
Loaded at $106 (SWI Vector)
Installs into the SWI vector, a jump to the code loaded from segment1 (JMP $1DA).

Segment 3:
Loaded at $16A (RVEC4)
Installs an SWI opcode ($3F) into the RAM Hook called by Console In.

Now when LOADM goes to read the first byte of the preamble for segment 4, it will execute the SWI which will vector to the code loaded from segment 1. The first thing that code does is restore the Console In RAM Hook and the SWI vector back to their normal state. It then takes over for LOADM and reads the remaining segments from the bin file. Since writes to memory are not verified, the issue with floating bits is eliminated.

This technique will even work on a CoCo1/2 since no patching of the ROM code is required; only the vectors in low RAM are temporarily modified. 

-----
Here is a hex dump of the data which can be inserted at the beginning of any bin file to install this custom loader:

00 00 41 01 DA CC 7E 3B B7 01 6A F7 01 06 8D 23
34 02 8D 2B 1F 02 8D 27 1F 01 A6 E0 27 0B 9F 9D
BD A4 2D BD AD 33 7E AC 73 8D 08 A7 80 31 3F 26
F8 20 DB BD A1 76 0D 70 27 0B C6 2E 7E AC 46 8D
00 8D F0 1E 89 39 00 00 03 01 06 7E 01 DA 00 00
01 01 6A 3F

-----
Here is the source code used to generate the above data (sorry if the column formatting doesn't come through correctly):

***** LOADER SEGMENT *****
LOADER    EQU    $1DA
          ORG    LOADER

* RESTORE RVEC4 AND SWI VECTOR ON ENTRY
          LDD    #$7E3B       A = JMP; B = RTI
          STA    $16A         RESTORE RVEC4
          STB    $106         RESTORE SWI VECTOR

* PARSE A PRE/POSTAMBLE
PREPOST   BSR    READBYTE     READ PRE/POSTAMBLE FLAG BYTE
          PSHS   A            SAVE IT ON THE STACK
          BSR    READWORD     READ SEGMENT SIZE INTO..
          TFR    D,Y          ..REGISTER Y
          BSR    READWORD     READ SEGMENT/EXEC ADDRESS INTO..
          TFR    D,X          ..REGISTER X
          LDA    ,S+          TEST FOR PRE/POSTAMBLE
          BEQ    DATABLK      BRANCH IF PREAMBLE
          STX    $9D          SAVE JUMP ADDRESS FOR EXEC
          JSR    $A42D        CLOSE FILE
          JSR    $AD33        CLEANUP THE STACK
          JMP    $AC73        RETURN TO BASIC
*         JMP    [$9D]        ALTERNATE: AUTO EXEC

* LOAD SEGMENT DATA
DATABLK   BSR    READBYTE     READ ONE DATA BYTE
          STA    ,X+          STORE BYTE, ADVANCE PTR
          LEAY   -1,Y         DECREMENT BYTES REMAINING COUNT
          BNE    DATABLK      CONTINUE UNTIL DONE
          BRA    PREPOST      PARSE NEXT PRE/POSTAMBLE

* READ ONE BYTE FROM FILE INTO ACCA. CHECK FOR 'INPUT PAST END OF FILE' ERROR.
READBYTE  JSR    $A176        READ BYTE INTO ACCA (CONSOLE IN)
          TST    $70          CHECK THE EOF FLAG
          BEQ    RETRN        RETURN IF NO ERROR
          LDB    #2*23        'IE ERROR' CODE
          JMP    $AC46        REPORT ERROR

* READ 16-BIT WORD FROM FILE INTO ACCD.
READWORD  BSR    READHALF     READ MS BYTE
READHALF  BSR    READBYTE     READ BYTE INTO ACCA
          EXG    A,B          SWAP A AND B
RETRN     RTS


***** SWI VECTOR SEGMENT *****
          ORG    $106
          JMP    LOADER


***** RVEC4 SEGMENT *****
          ORG    $16A
          SWI


_________________________________________________________________
Need to know the score, the latest news, or you need your Hotmail®-get your "fix".
http://www.msnmobilefix.com/Default.aspx


More information about the Coco mailing list