Костыльно поправлены RAM_ROUTINES в SP_128 для сохранения статуса прерываний в функции SWAP_ROM

This commit is contained in:
Tolik 2025-10-25 23:51:00 +10:00
parent a585ef51e5
commit 57cdd81dcb
3 changed files with 228 additions and 157 deletions

View File

@ -2,11 +2,14 @@
; *** SPECTRUM 128 ROM 0 DISASSEMBLY *** ; *** SPECTRUM 128 ROM 0 DISASSEMBLY ***
; ************************************** ; **************************************
INCLUDE 'Shared_Includes/macroses/macros.z80' INCLUDE 'Shared_Includes/macroses/macros.z80'
INCLUDE 'inc/rom_routines.inc'
DEFINE MODIFIED_SWAP
TST_PATCH_ADDR EQU #5CC0
; The Spectrum ROMs are copyright Amstrad, who have kindly given permission ; The Spectrum ROMs are copyright Amstrad, who have kindly given permission
; to reverse engineer and publish Spectrum ROM disassemblies. ; to reverse engineer and publish Spectrum ROM disassemblies.
; ===== ; =====
; NOTES ; NOTES
; ===== ; =====
@ -248,12 +251,12 @@
; These are held in the old ZX Printer buffer at #5B00-#5BFF. ; These are held in the old ZX Printer buffer at #5B00-#5BFF.
; Note that some of these names conflict with the system variables used by the ZX Interface 1. ; Note that some of these names conflict with the system variables used by the ZX Interface 1.
SWAP_ROM EQU #5B00 ; 20 Swap paging subroutine. ;SWAP_ROM EQU #5B00 ; 20 Swap paging subroutine.
YOUNGER EQU #5B14 ; 9 Return paging subroutine. ;YOUNGER EQU #5B14 ; 9 Return paging subroutine.
ONERR EQU #5B1D ; 18 Error handler paging subroutine. ;ONERR EQU #5B1D ; 18 Error handler paging subroutine.
PIN EQU #5B2F ; 5 RS232 input pre-routine. ;PIN EQU #5B2F ; 5 RS232 input pre-routine.
POUT EQU #5B34 ; 22 RS232 token output pre-routine. This can be patched to bypass the control code filter. ;POUT EQU #5B34 ; 22 RS232 token output pre-routine. This can be patched to bypass the control code filter.
POUT2 EQU #5B4A ; 14 RS232 character output pre-routine. ;POUT2 EQU #5B4A ; 14 RS232 character output pre-routine.
TARGET EQU #5B58 ; 2 Address of subroutine to call in ROM 1. TARGET EQU #5B58 ; 2 Address of subroutine to call in ROM 1.
RETADDR EQU #5B5A ; 2 Return address in ROM 0. RETADDR EQU #5B5A ; 2 Return address in ROM 0.
BANK_M EQU #5B5C ; 1 Copy of last byte output to I/O port #7FFD. BANK_M EQU #5B5C ; 1 Copy of last byte output to I/O port #7FFD.
@ -922,28 +925,49 @@ NMI_POINT:
; RET ; ; RET ;
; ENT ; ENT
;SWAP_ROM
;L006B Paging subroutine
RAM_ROUTINES: RAM_ROUTINES:
L006B: PUSH AF ; Save AF and BC. DISP BASIC_FN.x128.ROM_SWAP
SWAP_ROM:
IFNDEF MODIFIED_SWAP
PUSH AF ; Save AF and BC.
PUSH BC ; PUSH BC ;
LD BC,#7FFD ; LD BC,$7FFD ;
LD A,(BANK_M) ; #5B5C. LD A,(BANK_M) ; $5B5C.
XOR #10 ; Select other ROM. .PRESENCE: XOR $10 ; Select other ROM.
DI ; Disable interrupts whilst switching ROMs. DI ; Disable interrupts whilst switching ROMs.
LD (BANK_M),A ; #5B5C. LD (BANK_M),A ; $5B5C.
OUT (C),A ; Switch to the other ROM. OUT (C),A ; Switch to the other ROM.
EI ; EI ;
POP BC ; Restore BC and AF. POP BC ; Restore BC and AF.
POP AF ; POP AF ;
RET ; RET ;
.Size EQU $-L006B ELSE
PUSH AF ; Save AF and BC.
PUSH BC ;
LD A,R
PUSH AF
LD A,(BANK_M) ; $5B5C.
.PRESENCE: XOR #10 ; Select other ROM.
CALL TST_KOSTYL
POP AF
JP PO,TST_KOSTYL2.no_EI
JR TST_KOSTYL2
;
RET ; ­  ¢á直© á«ãç ©
BLOCK #7F-$$$,0
ENDIF
; ˆá¯®«ì§ã¥âáï ¢ L3B49 SP__48.ASM
ASSERT SWAP_ROM.PRESENCE = #5B08, "ERROR: SWAP_ROM.PRESENCE NOT GOOD"
; --------------------------- ; ---------------------------
; Return to Other ROM Routine (copied to #5B14) ; Return to Other ROM Routine (copied to #5B14)
; --------------------------- ; ---------------------------
; Switch to the other ROM from that currently paged in ; Switch to the other ROM from that currently paged in
; and then return to the address held in RETADDR. ; and then return to the address held in RETADDR.
;YOUNGER YOUNGER:
L007F: CALL SWAP_ROM ; #5B00. Toggle to the other ROM. L007F: CALL SWAP_ROM ; #5B00. Toggle to the other ROM.
PUSH HL ; PUSH HL ;
LD HL,(RETADDR) ; #5B5A. LD HL,(RETADDR) ; #5B5A.
@ -955,9 +979,10 @@ L007F: CALL SWAP_ROM ; #5B00. Toggle to the other ROM.
; --------------------- ; ---------------------
; This error handler routine switches back to ROM 0 and then ; This error handler routine switches back to ROM 0 and then
; executes the routine pointed to by system variable TARGET. ; executes the routine pointed to by system variable TARGET.
;L0088:
;ONERR ONERR:
L0088: DI ; Ensure interrupts are disabled whilst paging. IFNDEF MODIFIED_SWAP
DI ; Ensure interrupts are disabled whilst paging.
LD A,(BANK_M) ; #5B5C. Fetch current paging configuration. LD A,(BANK_M) ; #5B5C. Fetch current paging configuration.
AND #EF ; Select ROM 0. AND #EF ; Select ROM 0.
LD (BANK_M),A ; #5B5C. Save the new configuration LD (BANK_M),A ; #5B5C. Save the new configuration
@ -965,6 +990,19 @@ L0088: DI ; Ensure interrupts are disabled whilst paging.
OUT (C),A ; Switch to ROM 0. OUT (C),A ; Switch to ROM 0.
EI ; EI ;
JP L00C3 ; Jump to #00C3 (ROM 0) to continue. JP L00C3 ; Jump to #00C3 (ROM 0) to continue.
ELSE
LD A,(BANK_M) ; $5B5C. Fetch current paging configuration.
AND $EF ; Select ROM 0.
CALL TST_KOSTYL
JR .exit
TST_KOSTYL2: EI
.no_EI: POP BC ; Restore BC and AF.
POP AF ;
RET
ONERR.exit: EI ;
JP L00C3 ; Jump to $00C3 (ROM 0) to continue.
ENDIF
; ------------------------- ; -------------------------
; 'P' Channel Input Routine (copied to #5B2F) ; 'P' Channel Input Routine (copied to #5B2F)
@ -973,9 +1011,9 @@ L0088: DI ; Ensure interrupts are disabled whilst paging.
; It causes ROM 0 to be paged in so that the new RS232 routines ; It causes ROM 0 to be paged in so that the new RS232 routines
; can be accessed. ; can be accessed.
;PIN PIN:
L009A: LD HL,L06D8 ; RS232 input routine within ROM 0. L009A: LD HL,L06D8 ; RS232 input routine within ROM 0.
JR L00A2 ; JR POUT.L00A2 ;
; -------------------------- ; --------------------------
; 'P' Channel Output Routine (copied to #5B34) ; 'P' Channel Output Routine (copied to #5B34)
@ -984,11 +1022,11 @@ L009A: LD HL,L06D8 ; RS232 input routine within ROM 0.
; It causes ROM 0 to be paged in so that the new RS232 routines ; It causes ROM 0 to be paged in so that the new RS232 routines
; can be accessed. ; can be accessed.
; Entry: A=Byte to send. ; Entry: A=Byte to send.
;L009F:
;POUT POUT:
L009F: LD HL,L07CA ; RS232 output routine within ROM 0. IFNDEF MODIFIED_SWAP
LD HL,L07CA ; RS232 output routine within ROM 0.
L00A2: EX AF,AF' ; Save AF registers. .L00A2: EX AF,AF' ; Save AF registers.
LD BC,#7FFD ; LD BC,#7FFD ;
LD A,(BANK_M) ; #5B5C. Fetch the current paging configuration LD A,(BANK_M) ; #5B5C. Fetch the current paging configuration
PUSH AF ; and save it. PUSH AF ; and save it.
@ -997,16 +1035,31 @@ L00A2: EX AF,AF' ; Save AF registers.
LD (BANK_M),A ; #5B5C. Store the new paging configuration. LD (BANK_M),A ; #5B5C. Store the new paging configuration.
OUT (C),A ; Switch to ROM 0. OUT (C),A ; Switch to ROM 0.
JP L05E6 ; Jump to the RS232 channel input/output handler routine. JP L05E6 ; Jump to the RS232 channel input/output handler routine.
ELSE
LD HL,L07CA ; RS232 output routine within ROM 0.
.L00A2: EX AF,AF' ; Save AF registers.
LD A,(BANK_M) ; #5B5C. Fetch the current paging configuration
PUSH AF ; and save it.
AND #EF ; Select ROM 0.
;
JR TST_KOSTYL3
;
TST_KOSTYL: LD BC,#7FFD ;
DI ; Ensure interrupts are disabled whilst paging.
LD (BANK_M),A ; #5B5C. Store the new paging configuration.
OUT (C),A ; Switch to ROM 0.
RET
ENDIF
; ------------------------ ; ------------------------
; 'P' Channel Exit Routine (copied to #5B4A) ; 'P' Channel Exit Routine (copied to #5B4A)
; ------------------------ ; ------------------------
; Used when returning from a channel 'P' read or write operation. ; Used when returning from a channel 'P' read or write operation.
; It causes the original ROM to be paged back in and returns back to ; It causes the original ROM to be paged back in and returns back to
; the calling routine. ; the calling routine.
;L00B5:
;POUT2 POUT2:
L00B5: EX AF,AF' ; Save AF registers. For a read, A holds the byte read and the flags the success status. IFNDEF MODIFIED_SWAP
EX AF,AF' ; Save AF registers. For a read, A holds the byte read and the flags the success status.
POP AF ; Retrieve original paging configuration. POP AF ; Retrieve original paging configuration.
LD BC,#7FFD ; LD BC,#7FFD ;
DI ; Ensure interrupts are disabled whilst paging. DI ; Ensure interrupts are disabled whilst paging.
@ -1015,6 +1068,21 @@ L00B5: EX AF,AF' ; Save AF registers. For a read, A holds the byte read
EI ; EI ;
EX AF,AF' ; Restore AF registers. For a read, A holds the byte read and the flags the success status. EX AF,AF' ; Restore AF registers. For a read, A holds the byte read and the flags the success status.
RET RET
ELSE
EX AF,AF' ; Save AF registers. For a read, A holds the byte read and the flags the success status.
POP AF ; Retrieve original paging configuration.
CALL TST_KOSTYL
EI ;
EX AF,AF' ; Restore AF registers. For a read, A holds the byte read and the flags the success status.
RET
;
TST_KOSTYL3:
LD BC,L05E6
PUSH BC
JR TST_KOSTYL
ENDIF
;
ENT
RAM_ROUTINES.Size EQU $-RAM_ROUTINES RAM_ROUTINES.Size EQU $-RAM_ROUTINES
;<<<<<<<<<<<<<<<<<<<<<<<<< End of RAM Routines >>>>>>>>>>>>>>>>>>>>>>>>>; ;<<<<<<<<<<<<<<<<<<<<<<<<< End of RAM Routines >>>>>>>>>>>>>>>>>>>>>>>>>;
@ -1054,7 +1122,10 @@ L00C9: LD A,B ;
LD HL,#C000 ; Start of the current RAM bank. LD HL,#C000 ; Start of the current RAM bank.
LD DE,#C001 ; LD DE,#C001 ;
LD BC,#3FFF ; All 16K of RAM bank. LD BC,#3FFF ; All 16K of RAM bank.
;!TEST
LD A,#FF ; LD A,#FF ;
;LD A,C
;
LD (HL),A ; Store #FF into RAM location. LD (HL),A ; Store #FF into RAM location.
CP (HL) ; Check RAM integrity. CP (HL) ; Check RAM integrity.
JR NZ,L0131 ; Jump if RAM error found. JR NZ,L0131 ; Jump if RAM error found.
@ -1069,7 +1140,6 @@ L00C9: LD A,B ;
DJNZ L00C9 ; Repeat for other RAM banks. DJNZ L00C9 ; Repeat for other RAM banks.
LD (ROW01),A ; #5B88. Signal no communications in progress to the keypad. LD (ROW01),A ; #5B88. Signal no communications in progress to the keypad.
LD C,#FD ; LD C,#FD ;
LD D,#FF ; LD D,#FF ;
LD E,#BF ; LD E,#BF ;
@ -1077,11 +1147,15 @@ L00C9: LD A,B ;
LD A,#0E ; LD A,#0E ;
OUT (C),A ; Select AY register 14. OUT (C),A ; Select AY register 14.
LD B,E ; BC=#BFFD. LD B,E ; BC=#BFFD.
;!TEST
LD A,#FF ; LD A,#FF ;
OUT (C),A ; Set AY register 14 to #FF. This will force a communications reset to the keypad if present. OUT (C),A ; Set AY register 14 to #FF. This will force a communications reset to the keypad if present.
JR L0137 ; Jump ahead to continue. JR L0137 ; Jump ahead to continue.
;OUT (C),D
L00FF: DB #00 ; [Spare byte] ;JR L0137
;
_mInfoBLOCK #0100 - $,0
;L00FF: DB #00 ; [Spare byte]
; ==================== ; ====================
@ -1166,7 +1240,7 @@ L0137: LD B,D ; Complete setting up the sound chip registers.
LD HL,#2BEC ; LD HL,#2BEC ;
LD A,#01 ; AHL=Free space in RAM disk. LD A,#01 ; AHL=Free space in RAM disk.
LD (SFSPACE),HL ; #5B85. Current address. LD (SFSPACE),HL ; #5B85. Current address.
LD (SFSPACE+2),A ; #5B87. Current RAM bank. LD (SFSPACE+2),A; #5B87. Current RAM bank.
LD A,#05 ; LD A,#05 ;
CALL L1C64 ; Page in logical RAM bank 5 (physical RAM bank 0). CALL L1C64 ; Page in logical RAM bank 5 (physical RAM bank 0).
@ -1178,7 +1252,7 @@ L0137: LD B,D ; Complete setting up the sound chip registers.
LD BC,#00A8 ; There are 21 User Defined Graphics to copy. LD BC,#00A8 ; There are 21 User Defined Graphics to copy.
EX DE,HL ; Swap so destination is #FFFF. EX DE,HL ; Swap so destination is #FFFF.
RST #28 ; RST #28 ;
DW MAKE_ROOM+#000C ; Calling this address (LDDR/RET) in the main ROM DW MAKE_ROOM+#000C; Calling this address (LDDR/RET) in the main ROM
; cleverly copies the 21 characters to the end of RAM. ; cleverly copies the 21 characters to the end of RAM.
EX DE,HL ; Transfer DE to HL. EX DE,HL ; Transfer DE to HL.
@ -9313,10 +9387,6 @@ L2330: CALL L18A1 ; Ensure end-of-statement or end-of-line.
;ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ; ;ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ;
;ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ; ;ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ;
; ------------------------------ ; ------------------------------
; Main Menu - Tape Loader Option ; Main Menu - Tape Loader Option
; ------------------------------ ; ------------------------------
@ -14054,9 +14124,9 @@ L335F: LD HL,#0000 ; Signal no line number of command.
LD (#FC9F),HL ; Signal no further character to fetch from the BASIC line within the program area. LD (#FC9F),HL ; Signal no further character to fetch from the BASIC line within the program area.
LD (#FCA1),HL ; Signal no further character to fetch from the Keyword Construction Buffer. LD (#FCA1),HL ; Signal no further character to fetch from the Keyword Construction Buffer.
LD HL,RAM_Routines ; Source for Insert Keyword Representation Into Keyword Construction Buffer routine. LD HL,RAM_Routines2 ; Source for Insert Keyword Representation Into Keyword Construction Buffer routine.
LD DE,#FCAE ; Destination for Insert Keyword Representation Into Keyword Construction Buffer routine. LD DE,#FCAE ; Destination for Insert Keyword Representation Into Keyword Construction Buffer routine.
LD BC,RAM_Routines.Size LD BC,RAM_Routines2.Size
LDIR ; Copy the routine to RAM bank 7 at address #FCAE. LDIR ; Copy the routine to RAM bank 7 at address #FCAE.
RET ; RET ;
@ -14075,7 +14145,7 @@ L335F: LD HL,#0000 ; Signal no line number of command.
; DE=Insertion address within Keyword Construction Buffer. ; DE=Insertion address within Keyword Construction Buffer.
; ;
; Copied to physical RAM bank 7 at #FCAE-#FCFC by subroutine at #335F (ROM 0). ; Copied to physical RAM bank 7 at #FCAE-#FCFC by subroutine at #335F (ROM 0).
RAM_Routines: RAM_Routines2:
L3374: DI ; Disable interrupts whilst paging. L3374: DI ; Disable interrupts whilst paging.
LD BC,#7FFD ; LD BC,#7FFD ;
@ -14260,7 +14330,7 @@ L3426: LD A,B ; Fetch the character code of the matching token (#00
OUT (C),D ; OUT (C),D ;
EI ; Re-enable interrupts. EI ; Re-enable interrupts.
RET ; <<< Last byte copied to RAM >>> RET ; <<< Last byte copied to RAM >>>
RAM_Routines.Size EQU $-RAM_Routines RAM_Routines2.Size EQU $-RAM_Routines2
; --------------------------------------------------------------------- ; ---------------------------------------------------------------------
; Create Next Line Number Representation in Keyword Construction Buffer ; Create Next Line Number Representation in Keyword Construction Buffer
; --------------------------------------------------------------------- ; ---------------------------------------------------------------------

View File

@ -137,8 +137,8 @@ CONT_5:
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
REDIR_RST38:
_mInfoBLOCK #38-$,#FF _mInfoBLOCK #38-$,#FF
REDIR_RST38:
; JP RST38X ; JP RST38X
; EI ; EI
; RET ; RET

View File

@ -7,7 +7,8 @@
; The Spectrum ROMs are copyright Amstrad, who have kindly given permission ; The Spectrum ROMs are copyright Amstrad, who have kindly given permission
; to reverse engineer and publish ROM disassemblies. ; to reverse engineer and publish ROM disassemblies.
; DEFINE NEW_TAP_PROC SWAP_ROM EQU #5B00 ; 20 Swap paging subroutine for BASIC 128 ROM
; ===== ; =====
; NOTES ; NOTES
; ===== ; =====
@ -19166,7 +19167,7 @@ L3B46: LD HL,#010F ; Vector table entry in Editor ROM -> JP #03A2
; Return to Editor ROM at address in HL ; Return to Editor ROM at address in HL
L3B49: EX (SP),HL ; Change the return address L3B49: EX (SP),HL ; Change the return address
JP #5B00 ; Page Editor ROM and return to the address on the stack JP SWAP_ROM ; Page Editor ROM and return to the address on the stack
; ------------------------------------- ; -------------------------------------
; STATEMENT INTERPRETATION RETURN PATCH ; STATEMENT INTERPRETATION RETURN PATCH