Костыльно поправлены 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 ***
; **************************************
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
; to reverse engineer and publish Spectrum ROM disassemblies.
; =====
; NOTES
; =====
@ -248,12 +251,12 @@
; 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.
SWAP_ROM EQU #5B00 ; 20 Swap paging subroutine.
YOUNGER EQU #5B14 ; 9 Return paging subroutine.
ONERR EQU #5B1D ; 18 Error handler paging subroutine.
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.
POUT2 EQU #5B4A ; 14 RS232 character output pre-routine.
;SWAP_ROM EQU #5B00 ; 20 Swap paging subroutine.
;YOUNGER EQU #5B14 ; 9 Return paging subroutine.
;ONERR EQU #5B1D ; 18 Error handler paging subroutine.
;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.
;POUT2 EQU #5B4A ; 14 RS232 character output pre-routine.
TARGET EQU #5B58 ; 2 Address of subroutine to call in ROM 1.
RETADDR EQU #5B5A ; 2 Return address in ROM 0.
BANK_M EQU #5B5C ; 1 Copy of last byte output to I/O port #7FFD.
@ -922,28 +925,49 @@ NMI_POINT:
; RET ;
; ENT
;SWAP_ROM
;L006B Paging subroutine
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 ;
LD BC,#7FFD ;
LD A,(BANK_M) ; #5B5C.
XOR #10 ; Select other ROM.
LD BC,$7FFD ;
LD A,(BANK_M) ; $5B5C.
.PRESENCE: XOR $10 ; Select other ROM.
DI ; Disable interrupts whilst switching ROMs.
LD (BANK_M),A ; #5B5C.
LD (BANK_M),A ; $5B5C.
OUT (C),A ; Switch to the other ROM.
EI ;
POP BC ; Restore BC and AF.
POP AF ;
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)
; ---------------------------
; Switch to the other ROM from that currently paged in
; and then return to the address held in RETADDR.
;YOUNGER
YOUNGER:
L007F: CALL SWAP_ROM ; #5B00. Toggle to the other ROM.
PUSH HL ;
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
; executes the routine pointed to by system variable TARGET.
;ONERR
L0088: DI ; Ensure interrupts are disabled whilst paging.
;L0088:
ONERR:
IFNDEF MODIFIED_SWAP
DI ; Ensure interrupts are disabled whilst paging.
LD A,(BANK_M) ; #5B5C. Fetch current paging configuration.
AND #EF ; Select ROM 0.
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.
EI ;
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)
@ -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
; can be accessed.
;PIN
PIN:
L009A: LD HL,L06D8 ; RS232 input routine within ROM 0.
JR L00A2 ;
JR POUT.L00A2 ;
; --------------------------
; '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
; can be accessed.
; Entry: A=Byte to send.
;POUT
L009F: LD HL,L07CA ; RS232 output routine within ROM 0.
L00A2: EX AF,AF' ; Save AF registers.
;L009F:
POUT:
IFNDEF MODIFIED_SWAP
LD HL,L07CA ; RS232 output routine within ROM 0.
.L00A2: EX AF,AF' ; Save AF registers.
LD BC,#7FFD ;
LD A,(BANK_M) ; #5B5C. Fetch the current paging configuration
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.
OUT (C),A ; Switch to ROM 0.
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)
; ------------------------
; 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
; the calling routine.
;POUT2
L00B5: EX AF,AF' ; Save AF registers. For a read, A holds the byte read and the flags the success status.
;L00B5:
POUT2:
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.
LD BC,#7FFD ;
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 ;
EX AF,AF' ; Restore AF registers. For a read, A holds the byte read and the flags the success status.
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
;<<<<<<<<<<<<<<<<<<<<<<<<< End of RAM Routines >>>>>>>>>>>>>>>>>>>>>>>>>;
@ -1054,7 +1122,10 @@ L00C9: LD A,B ;
LD HL,#C000 ; Start of the current RAM bank.
LD DE,#C001 ;
LD BC,#3FFF ; All 16K of RAM bank.
;!TEST
LD A,#FF ;
;LD A,C
;
LD (HL),A ; Store #FF into RAM location.
CP (HL) ; Check RAM integrity.
JR NZ,L0131 ; Jump if RAM error found.
@ -1069,7 +1140,6 @@ L00C9: LD A,B ;
DJNZ L00C9 ; Repeat for other RAM banks.
LD (ROW01),A ; #5B88. Signal no communications in progress to the keypad.
LD C,#FD ;
LD D,#FF ;
LD E,#BF ;
@ -1077,11 +1147,15 @@ L00C9: LD A,B ;
LD A,#0E ;
OUT (C),A ; Select AY register 14.
LD B,E ; BC=#BFFD.
;!TEST
LD A,#FF ;
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.
L00FF: DB #00 ; [Spare byte]
;OUT (C),D
;JR L0137
;
_mInfoBLOCK #0100 - $,0
;L00FF: DB #00 ; [Spare byte]
; ====================
@ -9313,10 +9387,6 @@ L2330: CALL L18A1 ; Ensure end-of-statement or end-of-line.
;ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ;
;ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ;
; ------------------------------
; 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 (#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 BC,RAM_Routines.Size
LD BC,RAM_Routines2.Size
LDIR ; Copy the routine to RAM bank 7 at address #FCAE.
RET ;
@ -14075,7 +14145,7 @@ L335F: LD HL,#0000 ; Signal no line number of command.
; DE=Insertion address within Keyword Construction Buffer.
;
; 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.
LD BC,#7FFD ;
@ -14260,7 +14330,7 @@ L3426: LD A,B ; Fetch the character code of the matching token (#00
OUT (C),D ;
EI ; Re-enable interrupts.
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
; ---------------------------------------------------------------------

View File

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

View File

@ -7,7 +7,8 @@
; The Spectrum ROMs are copyright Amstrad, who have kindly given permission
; to reverse engineer and publish ROM disassemblies.
; DEFINE NEW_TAP_PROC
SWAP_ROM EQU #5B00 ; 20 Swap paging subroutine for BASIC 128 ROM
; =====
; 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
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