I have reverse engineered ArgDub's driver and yes indeed a lot of that code is recognizable...
Why going such a long and difficult way?
18 years ago it takes me half hour to patch free source code example for X25160 eepom from minimon driver directory and compile new driver for 95040.
Now I looked for and found it in my archive...
; My driver to work with SPI EEPROM in ECUs
; 512-byte EEPROM sampling line - P4.7
; The driver is written rather carelessly, it is
; a rewritten version of the driver from the MiniMon kit, in which
; I added a group write function to EEPROM from RAM, using
; script-and this will be done much faster than rather curves
; operations of working with flash by means of the Minimon itself (by byte it works
; extremely slowly).
$SEGMENTED
$MOD167
$NoPaging
assume DPP3:system
; Driver function codes
_WriteSPI equ 00h ; programming one byte
_ReadSPI equ 36h ; read block
_WriteAll equ 37h ; block record
_GetState equ 06h ; read state
; SPI EEPROM Commands
_EEWrite equ 02h ; Write
_EERead equ 03h ; Read
_EEState equ 05h ; Read Status Register
_EEWREN equ 06h ; Enable Write
; MCU registers
P3 defr 0FFC4h ; port P3
DP3 defr 0FFC6h ; its direction lines
P6 defr 0FFC8h ; port P4
DP6 defr 0FFCAh ; its direction lines
SSCRIC defr 0FF74h
SSCCON defr 0FFB2h ; SSC configuration register
SSCTB defr 0F0B0h ; SSC transmit register
SSCRB defr 0F0B2h ; SSC receive register
SSCBR defr 0F0B4h ; SSC baudrate
SSCRIR equ SSCRIC.7 ; exchange completion flag
SPI_CS equ P6.3 ; CS line
SPI_CS_PD equ DP6.3 ; port direction control
DriverC section code at 0FD00h
; ------------------------------------------------- ---------------------
; The beginning of the driver itself - initializing ports
; r8 - operation code;
; r9 - block length in bytes;
; r10 - low bytes of the RAM address;
; r13 - low bytes of the EEPROM address;
; r15 - return code on exit
; ------------------------------------------------- ---------------------
DriverP proc far
; Deselect EEPROM
bset SPI_CS ; -CS=1
nop
bset SPI_CS_PD ; and switch the line to output
; SPI init
extr #1
mov SSCBR,#000Bh ; baudrate speed in the ECU firmware
mov SSCCON,#0C037h ; configuration
bfldh P3,#023h,#23h ; Set MRST=1, MTSR=1, SCLK=1
bfldh DP3,#023h,#22h ; Set MRST=input, MTSR=output, SCLK=output
callr Delay
; ------------------------------------------------- ---------------------
; Programming one byte
; r8 - opcode
; r9 - block length in bytes (for programming - 1, byte!);
; r10 - low bytes of the source block address
; r13 - low bytes of the address in the EEPROM
; r15 - return code on exit
; ------------------------------------------------- ---------------------
cmp r8,#_WriteSPI ; write byte?
jmp cc_ne,Cmd1 ; no
mov r8,#_WriteAll ; block write command
mov r9,#1 ; and the explicit length is 1 byte
xor r10,r13 ; addresses in registries r10 and r13
xor r13,r10 ; swapping
xor r10,r13
; ------------------------------------------------- ---------------------
; Writing a block from RAM to EEPROM
; r8 - operation code;
; r9 - block length in bytes (for programming - 1, byte!);
; r10 - EEPROM address
; r13 - RAM address
; r15 - return code on exit
; ------------------------------------------------- ---------------------
Cmd1:
cmp r8,#_WriteAll ; block recording?
jmp cc_ne,Cmd2 ; no
Block:
bclr SPI_CS ; -CS
mov r3,#_EEState
callr SendRecSSC status register read command
callr SendRecSSC ; send dummy byte, receive data byte
bset SPI_CS ; remove the sample
and r4,#01h ; WIP control
jmp cc_nz,Block ; busy ?
exts #0,#1
movb rl5,[r13] ; byte of data from RAM
bclr SPI_CS ; EEPROM selection
mov r3,#_EEWREN ; recording enable
callr SendRecSSC
bset SPI_CS ; switch off EEPROM selection
callr Delay
bclr SPI_CS ; EEPROM selection
mov r6,r10 ; EEPROM address
and r6,#0700h ; A8,A9,A10
shr r6,#5 ; shift
mov r3,#_EEWrite
or r3,r6 ; add A8 in command
callr SendRecSSC
mov r3,r10 ; transmit byte
callr SendRecSSC ; address
mov r3,r5 ; data to write in low byte r5
callr SendRecSSC ;
bset SPI_CS ; switch off EEPROM selection
add r13,#1 ; next byte in RAM
add r10,#1 ; next EEPROM address
sub r9,#1
jmp cc_nz,Block
mov r15,#0 ; completion code
rets
; ------------------------------------------------- ---------------------
; Reading SPI EEPROM to buffer
; r8 - operation code;
; r9 is the length of the read block;
; r10 - address in EEPROM;
; r13 - buffer address;
; r15 - return code on exit
; ------------------------------------------------- ---------------------
Cmd2: cmp r8,#_ReadSPI ; reading a block?
jmp cc_ne,Cmd3 ; no
bclr SPI_CS ; -CS
mov r3,#_EERead
callr SendRecSSC ; read command
mov r3,r10 ; MSB of byte address
ror r3,#8
callr SendRecSSC
mov r3,r10 ; LSB of byte address
callr SendRecSSC
sub r9,#1
; mov r5,#0F200h ; fixed buffer addr=F200
mov r5,r13 ; buffer addr
addc r5,r10 ; + offset
ReadLoop:
callr SendRecSSC ; read byte
exts #0,#1
movb [r5],rl4 ; store byte in buffer
add r5,#1 ; next address
cmpd1 r9,#0
jmpr cc_ugt,ReadLoop ; until r9 > 0
bset SPI_CS ; switch off EEPROM selection
mov r15,#0 ; completion code
rets
; ------------------------------------------------- ---------------------
; Reading EEPROM status, r9 returns status value
; ------------------------------------------------- ---------------------
Cmd3:
; cmp r8,#_GetState
; jmp cc_ne,CmdC
;
Read_S:
bclr SPI_CS ; -CS
mov R3,#_EEState
callr SendRecSSC ; status register read command
callr SendRecSSC ; send dummy byte, receive data byte
mov r9,r4 ; in r9
bset SPI_CS ; switch off EEPROM selection
mov r15,#0 ; completion code
rets
; ------------------------------------------------- ---------------------
; Unrecognized command, exit c r15 = 1
; ------------------------------------------------- ---------------------
CmdC: mov r15,#1
rets
DriverP endp
;----------------------------------------------------------------------
; Small delay ...
;----------------------------------------------------------------------
Delay proc near
nop
nop
nop
nop
ret
Delay endp
; ------------------------------------------------- ---------------------
; SSC work program - data reception and transmission
; r3 - transmitted value; r4 - received value
; ------------------------------------------------- ---------------------
SendRecSSC proc near
bclr SSCRIR ; reset flag
mov SSCTB,r3 ; transmission start
SSCWait:
jnb SSCRIR,SSCWait ; waiting for completion
mov r4,SSCRB ; received data
ret
SendRecSSC endp
;----------------------------------------------------------------------
DriverC ends
end