%include "header.asm"
kernel_thunk:
HalReadSMBusValue: dd 0x80000000 + 45
HalReturnToFirmware: dd 0x80000000 + 49
HalWriteSMBusValue: dd 0x80000000 + 50
LaunchDataPage: dd 0x80000000 + 164
MmAllocateContiguousMemory: dd 0x80000000 + 165
MmPersistContiguousMemory: dd 0x80000000 + 178
dd 0 ; end of table
align 4
start: cld
fan: push word 0026h ; speed 10-50 (00Ah-032h)
push byte 0
push byte 6 ; fan_register
push byte 20h ; pic_address
call dword [HalWriteSMBusValue]
push byte 1
push byte 0
push byte 5 ; fan_mode
push byte 20h ; pic_address
call dword [HalWriteSMBusValue]
;----------------------------------------
mov eax,tray_data1 ; get tray state
push eax
push byte 0
push byte 3
push byte 20h
call dword [HalReadSMBusValue]
cmp byte [tray_data1], 10h; 10h = open, anything else is closed
je short .t_opn
mov eax, 00FFh ; ORANGE led "closed"
call set_led ; go set it
jmp short do_xbe ; normal boot tray_data2 is zero
;----------------------------------------
.t_opn mov eax,00F0h ; RED led $F0 "open for now"
call set_led ; go set it
;-------
mov eax,0x1FFFFFFF
dly_0 dec eax
jnz short dly_0 ; ~ 1 sec
;----------------------------------------
push byte 1 ; close tray
push byte 0
push byte 0Ch ; tray_mode
push byte 20h ; pic_address
call dword [HalWriteSMBusValue]
;----------------------------------------
TS_lp: mov eax,0x01FFFFFF
dly_1 dec eax
jnz short dly_1 ; ~ 1/15 sec
;-------
mov eax, tray_data2 ; read after tray is closed
push eax
push byte 0
push byte 3
push byte 20h
call dword [HalReadSMBusValue]
;-------
cmp byte [tray_data2],40h; 40h = no disk
je short do_xbe ; we need to boot alt from HDD
cmp byte [tray_data2],60h; 60h = game disk
jne short TS_lp ; loop till disk is read
;-------
mov eax, 00EBh ; Orange Red Orange Green
call set_led ; change it (xmas tree) and boot Cdrom
mov esi,[LaunchDataPage]
mov ebx,[esi]
jmp short go_cd ; boot cd default.xbe
;----------------------------------------
do_xbe: mov esi,[LaunchDataPage]
mov edi,0x0100 ; bytes to hold xbe path

??
mov ebx,[esi]
test ebx,ebx
jnz .memok
push edi
call dword [MmAllocateContiguousMemory]
mov ebx,eax
mov [esi],eax
.memok: push byte 1
push edi
push ebx
call dword [MmPersistContiguousMemory]
mov edi,ebx
xor eax,eax
mov ecx,0x0100 ; bytes to zero

??
rep stosd
or dword [ebx],byte -1
mov [ebx+4],eax
lea edi,[ebx+8]
cmp byte [tray_data2],0h; if zero tray was closed at boot
je short bt_nm ; boot normal
lea esi,[xbestr_nd]
push byte XBESTRLEN_ND; boot no disk xbe
jmp short go_xbe
;-------
bt_nm lea esi,[xbestr]
push byte XBESTRLEN
go_xbe pop ecx
rep movsb
go_cd push byte 2
call dword [HalReturnToFirmware]
.inf: jmp short .inf
;----------------------------------------
set_led:
push eax ; must be dword size
push byte 0
push byte 8 ; led_register
push byte 20h ; pic_address
call dword [HalWriteSMBusValue]
push byte 1
push byte 0
push byte 7 ; led_mode
push byte 20h ; pic_address
call dword [HalWriteSMBusValue]
ret
;--------------------------------------------------------------------------------------
tray_data1 dd 0 ; put tray data here (yes, it's in the code section)
tray_data2 dd 0 ; 2nd read if tray was open at boot (after close)
align 16
xbestr db '\Device\Harddisk0\Partition2;NKpatcher.xbe',0
times 31 db 0 ;; tray closed > C:\NKpatcher
XBESTRLEN equ $-xbestr
align 16
xbestr_nd db '\Device\Harddisk0\Partition1\UDATA\4d530017\62d648ebf155;default.xbe',0
times 5 db 0 ;; > MA gamesave !!!!
XBESTRLEN_ND equ $-xbestr_nd
;--------------------------------------------------------------------------------------
%include "footer.asm"