Skip to content

Instantly share code, notes, and snippets.

@LightningStalker
Created February 23, 2026 18:30
Show Gist options
  • Select an option

  • Save LightningStalker/4acc911f8a17bb2183d3b7ea599942f9 to your computer and use it in GitHub Desktop.

Select an option

Save LightningStalker/4acc911f8a17bb2183d3b7ea599942f9 to your computer and use it in GitHub Desktop.
Press any key to reboot OS for PC
;******************************
; Press any key to reboot v2.1
; For flat assembler
; Project Crew™ 2/29/2008
;******************************
version equ '2.1'
format binary as 'ima'
include 'Ata_Atapi.inc' ; Use Craig Bamford's library
; for CD Eject functions
Load_Segment equ 7C00h
org Load_Segment ; 7C00h does it for boot sectors
use16
;******************************
; Realmode startup code.
;******************************
start:
xor ax,ax
mov ds,ax
mov es,ax
mov ss,ax
mov sp,Load_Segment
;******************************
; Print message.
;******************************
mov si,Message ; Point si to Message
call print ; Call subroutine to print message
;******************************
; Eject and wait for key press.
;******************************
call Eject_cd ; Call subroutine in Ata_Atapi.inc
mov ah,10h ; Read a keypress using extended
int 16h ; keyboard to include F11 & F12
call Close_cd ; Call subroutine in Ata_Atapi.inc
;******************************
; Reboot.
;******************************
push 40h ; Move 40h
pop ds ; Into ds
mov word [0072h], 1234h ; 1234h for warm reboot, 0000h for cold
push 0FFFBh ; 4 less than FFFF where we're going
push ds ; +40h to FFFF:0000. Genius loco, genius!
retf ; Blamo
;******************************
; Sub print.
;******************************
print:
mov ah,0Eh ; Request display
again1:
lodsb ; load a byte into AL from DS:SI
or al,al ; See if it's a zero
jz done1 ; Jump to label done1 if it is
int 10h ; Call interrupt service
jmp again1 ; Jump to label again1
done1:
ret ; Return
;******************************
; Strings
;******************************
Message db "The CD in your drive is not bootable.", 0Dh, 0Ah,\
"Please insert disc 1 to reload the system or remove this one to boot ",\
"into", 0dh, 0ah,\
"Windows.", 0Dh, 0Ah,\
0Dh, 0Ah,\
"Press any key to reboot.", 0
db "operating system v", version, " by Project Crew™"
;******************************
; Make program 510 bytes +
; 0xAA55
;******************************
times 510- ($-start) db 0 ; Fill current offset-start-510 with zeros
dw 0xAA55 ; Put magic number at end to get 512 Bytes
;=========================================================;
; Send Atapi Packet 01/06/06 ;
;---------------------------------------------------------;
; Dex4u OS V0.01 ;
; by Craig Bamford(Dex). ;
; ;
; Input: ;
; esi, points to 12 byte packet. ;
; ;
;=========================================================;
Send_Atapi_Packet:
xor dx,dx
mov bx,0xffff
mov cx,bx
mov dx,0x0177 ; Read Status = 7 + the base = 177
StatusReg1_1:
in al,dx ; Mov data from port to al
and al,0x80 ; Check bit 7(busy bit) ,loop if not 0
jz WriteCommand1_1 ; Jump to WriteCommand1_1 if al bit7 =0
loop StatusReg1_1 ; If al bit 7 =1,loop StatusReg1_1
ret
WriteCommand1_1:
dec dx
xor ax,ax ; Bit 4 ,0 to select primary drive, 1 to select secondary drive
out dx,al ; Write al to port (register)
mov cx,bx ; Mov cx, number of loops(bx=0xffff)
inc dx
StatusReg2_1:
in al,dx ; Mov data from port to al
and al,0x80 ; Check bit 7(busy bit) ,loop if not 0
jz WriteCommand2_1 ; Jump to WriteCommand2_1 if al bit7 =0
loop StatusReg2_1 ; If al bit 7 =1,loop StatusReg2_1
DeviceBusy_1: ; time out:-(
ret
;----------------------------------------------------;
; Write Command ;
;----------------------------------------------------;
WriteCommand2_1:
mov al,0xA0 ; Add the 8 bit code to al
out dx,al ; Write al to port (register)
mov cx,bx ; Mov cx, number of loops(bx=0xffff)
StatusReg3_1:
in al,dx ; Mov data from port to al
test al,0x80 ; Does bit 7 = 0 (busy bit)
jnz DrqErrorCheck1_1 ; Jump to "DrqErrorCheck1_1" if bit7 is 1
test al,0x08 ; Does bit3 = 0 (DRQ bit)
jnz WriteCommandPacket1_1 ; Jump to label if bit3 is 1,we can transfer data to port:-)
DrqErrorCheck1_1:
loop StatusReg3_1 ; Loop label
ret
;----------------------------------------------------;
; Write Command Packet ;
;----------------------------------------------------;
WriteCommandPacket1_1:
mov dx,0x0170 ; Read date/write = 0
mov cx,6 ; Mov number of words to mov into cx
WritePacket1_1:
lodsw ; Mov a word from packet to ax, inc esi 2
out dx,ax ; Write ax to port (register)
loop WritePacket1_1 ; Loop label
mov cx,bx ; Mov cx, number of loops
mov dx,0x0177 ; Read Status = 7 + the base = 177
StatusReg4_1:
in al,dx ; Mov data from port to al
test al,0x80 ; Does bit 7 = 0 (busy bit)
jnz DrqErrorCheck2_1 ; Jump to "DrqErrorCheck2_1" if bit7 is 1
ret
;----------------------------------------------------;
; Drq Error Check ;
;----------------------------------------------------;
DrqErrorCheck2_1:
push cx ; Save old cx
mov cx,bx ; Mov cx, number of loops(bx=0xffff)
BusyDelay_1: ; Label
nop ; Do a null operation(xchg ax,ax)
nop ; Do a null operation(xchg ax,ax)
nop ; Do a null operation(xchg ax,ax)
nop ; Do a null operation(xchg ax,ax)
loop BusyDelay_1 ; Loop label
pop cx ; Get old cx
loop StatusReg4_1 ; Loop label
error_1:
ret
;====================================================;
; Eject cd ;
;====================================================;
Eject_cd:
pusha
mov byte[packet+4],0x2
mov byte[packet+1],0x1
mov byte[packet+0],0x1b
mov si,packet
call Send_Atapi_Packet
popa
ret
;====================================================;
; Close cd ;
;====================================================;
Close_cd:
pusha
mov byte[packet+0],0x1b
mov byte[packet+1],0x1
mov byte[packet+4],0x3
mov si,packet
call Send_Atapi_Packet
popa
ret
;--------------------------------------------------------------------------------------------;
; Data ;
;--------------------------------------------------------------------------------------------;
packet:
db 0x0
db 0x0
db 0x0
db 0x0
db 0x0
db 0x0
db 0x0
db 0x0
db 0x0
db 0x0
db 0x0
db 0x0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment