; LAST UPDATE: 12.02.2024 savelij
TITLE "addon1.a80 ROM_RST81"
PHASE CPU0
JP $
DUPL 0x0008 - $,0xFF
JP $
DUPL 0x0010 - $,0xFF
JP $
DUPL ADR_SEL_ROM - $,0xFF
OUT (C),A ; 0014
NOP
RET
DUPL 0x0018 - $,0xFF
JP $
DUPL 0x0020 - $,0xFF
JP $
DUPL 0x0028 - $,0xFF
JP $
DUPL 0x0030 - $,0xFF
JP CALL2PAGE
DUPL ADR_PERFECT - $,0xFF
DW PERFECTCOM
DUPL 0x0038 - $,0xFF ; 0038
EI
RET
DUPL 0x003E - $,0xFF
EI
RET
DUPL 0x0040 - $,0xFF
JP INSTALL_NMIRST ; установка обработчиков NMI и RST
DUPL 0x0080 - $,0xFF
binclude ../../dec40.bin
DUPL 0x00FF - $,0xFF
DW 0x0038
PHASE $ + 0x4000
include rst8_data.a80
PHASE $ & 0x3FFF
DUPL (HIGH ($) + 1) * 0x100 - $,0xFF
BUF_CRC16_TABL DB 0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x81,0x91,0xA1,0xB1,0xC1,0xD1,0xE1,0xF1
DB 0x12,0x02,0x32,0x22,0x52,0x42,0x72,0x62,0x93,0x83,0xB3,0xA3,0xD3,0xC3,0xF3,0xE3
DB 0x24,0x34,0x04,0x14,0x64,0x74,0x44,0x54,0xA5,0xB5,0x85,0x95,0xE5,0xF5,0xC5,0xD5
DB 0x36,0x26,0x16,0x06,0x76,0x66,0x56,0x46,0xB7,0xA7,0x97,0x87,0xF7,0xE7,0xD7,0xC7
DB 0x48,0x58,0x68,0x78,0x08,0x18,0x28,0x38,0xC9,0xD9,0xE9,0xF9,0x89,0x99,0xA9,0xB9
DB 0x5A,0x4A,0x7A,0x6A,0x1A,0x0A,0x3A,0x2A,0xDB,0xCB,0xFB,0xEB,0x9B,0x8B,0xBB,0xAB
DB 0x6C,0x7C,0x4C,0x5C,0x2C,0x3C,0x0C,0x1C,0xED,0xFD,0xCD,0xDD,0xAD,0xB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,0x86,0xA7,0x40,0x61,0x02,0x23,0xCC,0xED,0x8E,0xAF,0x48,0x69,0x0A,0x2B
DB 0xF5,0xD4,0xB7,0x96,0x71,0x50,0x33,0x12,0xFD,0xDC,0xBF,0x9E,0x79,0x58,0x3B,0x1A
DB 0xA6,0x87,0xE4,0xC5,0x22,0x03,0x60,0x41,0xAE,0x8F,0xEC,0xCD,0x2A,0x0B,0x68,0x49
DB 0x97,0xB6,0xD5,0xF4,0x13,0x32,0x51,0x70,0x9F,0xBE,0xDD,0xFC,0x1B,0x3A,0x59,0x78
DB 0x88,0xA9,0xCA,0xEB,0x0C,0x2D,0x4E,0x6F,0x80,0xA1,0xC2,0xE3,0x04,0x25,0x46,0x67
DB 0xB9,0x98,0xFB,0xDA,0x3D,0x1C,0x7F,0x5E,0xB1,0x90,0xF3,0xD2,0x35,0x14,0x77,0x56
DB 0xEA,0xCB,0xA8,0x89,0x6E,0x4F,0x2C,0x0D,0xE2,0xC3,0xA0,0x81,0x66,0x47,0x24,0x05
DB 0xDB,0xFA,0x99,0xB8,0x5F,0x7E,0x1D,0x3C,0xD3,0xF2,0x91,0xB0,0x57,0x76,0x15,0x34
DB 0x4C,0x6D,0x0E,0x2F,0xC8,0xE9,0x8A,0xAB,0x44,0x65,0x06,0x27,0xC0,0xE1,0x82,0xA3
DB 0x7D,0x5C,0x3F,0x1E,0xF9,0xD8,0xBB,0x9A,0x75,0x54,0x37,0x16,0xF1,0xD0,0xB3,0x92
DB 0x2E,0x0F,0x6C,0x4D,0xAA,0x8B,0xE8,0xC9,0x26,0x07,0x64,0x45,0xA2,0x83,0xE0,0xC1
DB 0x1F,0x3E,0x5D,0x7C,0x9B,0xBA,0xD9,0xF8,0x17,0x36,0x55,0x74,0x93,0xB2,0xD1,0xF0
; быстрая (табличная) функция подсчёта CRC-16,
; IX = *DATA, HL = SIZE
; на выходе: -> HL = подсчитанное значение
CRC16_FAST LD B,H
LD C,L
LD HL,0xFFFF
EXX
PUSH HL
LD DE,BUF_CRC16_TABL
LD C,0
EXX
CRC16F0 LD A,(IX)
XOR H
INC IX
EXX
LD L,A
LD H,C
ADD HL,DE
LD A,(HL)
INC H
EXX
XOR L
LD H,A
EXX
LD A,(HL)
EXX
LD L,A
DEC BC
LD A,B
OR C
JP NZ,CRC16F0
EXX
POP HL
EXX
RET
; установка обработчиков RST 8 и NMI, инициализация переменных
INSTALL_NMIRST
ATMPORT WIN_A3,0x40 ; сняли зависимость от порта 7FFD
EVOPORT WIN_P6,0 ; включили страницу переменных
LD BC,FDD_EMU_PORT
XOR A
OUT (C),A ; сброс виртуальных дисководов
LD (B_PORT_VIRT),A
LD A,0xEF
IN A,(0xFE)
RRCA
JR NC,.L2
LD IX,CPU2+STACK_NMI
LD HL,0x40
CALL CRC16_FAST ; считаем CRC на месте обработчика
PUSH HL ; сохранили CRC
LD IX,CODE_NMIRST + STACK_NMI
LD HL,0x40
CALL CRC16_FAST
POP BC ; вернули ранее посчитанное CRC
XOR A
SBC HL,BC ; сравнили
JR Z,.L1 ; если совпало больше ничего не делаем
EVOPORT WIN_P3,RAM_PROFROM
LD HL,CPU0
CALL FILL_MEM ; очистка страницы ОЗУ PROFROM
; не совпало, первый запуск после включения питания или обработчики были испорчены
.L2 LD A,(HDDTIMEOUT) ; сохраняем ячейку вне зависимости от содежимого
LD HL,CPU3
CALL FILL_MEM ; очистка последней страницы RAM
LD (HDDTIMEOUT),A ; восстанавливаем ячейку
LD HL,CODE_NMIRST
LD DE,CPU6
LD BC,ENMI_SERVICE - ADR_SEL_ROM - CPU6
LDIR ; установили обработчики
LD (BUF_TABLVOL + 0xFE),BC ; сброс CRC таблицы найденных разделов
EVOPORT WIN_P3,RAM_MOUNTER ; включили страницу монтировщика образов
LD HL,CPU0
CALL FILL_MEM ; очистка страницы монтировщика образов
XOR A
LD (CPU6 + DEBUG_ONOFF),A ; 0 - DEBUGGER OFF
LD (FLAGS_DRV),A ; сброс флагов драйверов
LD A,CMOS_BYTE_00
LD BC,CMOSD_SET_ADR
OUT (C),A
LD BC,CMOSD_RD_WR
IN A,(C)
CALL LD_SET_FONT
LD A,VIRT_REAL_DRIVE
LD BC,CMOSD_SET_ADR
OUT (C),A
LD BC,CMOSD_RD_WR
IN A,(C)
LD (CPU2 + VIRT_BITS),A ; при ините монтируем только рамдиск
.L1
IF BUILD_DEBUG=1
ROMCALL UNPACK_STS,ROM_RST80
ENDIF
ROMCALL INIT_CMOS,ROM_RST82 ; проверка и инициализация CMOS при ошибке CRC
CALL SET4RESETFONT
IF 0;USB_ENABLE
EVOPORT WIN_P3,RAM_SCR_FONT ; страницы для драйвера
EVOPORT WIN_A2,ROM_RST83
LD HL,USB_DRV + CPU2 ; адрес драйвера
LD DE,OFFSET_USBDRV + CPU3 ; адрес работы
LD BC,ECOMUSBF - COMUSBF
LDIR
EVOPORT WIN_P6,0
ENDIF
LD BC,0xFF << 8 + PN_1F7
IN A,(C)
CP 0x50
LD A,1
JR Z,.L3
LD A,(HDDTIMEOUT)
DEC A
JR Z,.L5 ; если ячейка равна 1 задержку из CMOS игнорируем
LD H,HDD_TIMEOUT
ROMCALL READCMOS,ROM_RST82
AND A
LD A,1
JR Z,.L3
XOR A
.L4 ADD A,25
DEC L
JR NZ,.L4
.L3 LD (HDDTIMEOUT),A
.L5 LD HL,STEK_PAGES
LD (TEKPAGE),HL
LD HL,READ_KEYS
LD (ADR_INT),HL
LD BC,WIN_A0
XOR A
LD (CPU6 + FOR_RET),A
JP ADR_SEL_ROM
FILL_MEM EX DE,HL
LD HL,0
ADD HL,SP
EX DE,HL
LD SP,HL
LD HL,0
LD B,L
FILL_MEM1
REPT 0x20
PUSH HL
ENDM
DJNZ FILL_MEM1
EX DE,HL
LD SP,HL
RET
SETUP_FONT LD A,(RREG_A)
AND A
LD HL,ATM_FONT
JR Z,SET_FONT1
DEC A
LD HL,CP866_FONT
JR Z,SET_FONT1
DEC A
RET NZ
LD HL,(RREG_L)
JR SET_FONT1
SET4RESETFONT LD A,CMOS_BYTE_00
LD BC,CMOSD_SET_ADR
OUT (C),A
LD BC,CMOSD_RD_WR
IN A,(C)
LD L,A
AND M_RELOAD_FONT
RET NZ ; если 1, то шрифт не перезагружаем
LD A,L
LD_SET_FONT AND M_TYPE_FONT ; определение выбранного шрифта
LD HL,ATM_FONT ; 0 = шрифт ATM
JR Z,SET_FONT1
LD HL,CP866_FONT ; 1 = шрифт CP866
SET_FONT1 LD DE,CPU3 + OFFSET_BUFSYM
EVOPORT WIN_P3,RAM_SCR_FONT
PUSH DE
ROMCALL UNPACK,ROM_RST80
POP HL
LD BC,0x0800
LD D,C
LD E,C
PEC_ON M_SHADOW_BF+M_FONT_BF
LDIR
PEC_OFF M_FONT_BF
RET
CurrAdr := $
include nmi_service.a80
PHASE $ + CurrAdr
PERFECTCOM binclude perfpack_pack.bin
FREE_ADDON1 EQU 0x3FF6 - $
DUPL FREE_ADDON1,0xFF
DW FREE_ADDON1 ; размер свободного места
DB "ADDON1"
DW DATA_VERS