Created
May 1, 2020 15:02
-
-
Save lpproj/46a84f9626ded8be20685144f207466a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BITS 16 | |
CPU 8086 | |
%ifdef TEST | |
segment .text class=CODE | |
%else | |
segment .text | |
ORG 0 | |
%endif | |
Base_of_code: | |
%macro _org 1 | |
%if (($ - Base_of_code) > %1) | |
%error _org: too much code to fit within %1 | |
%endif | |
%if ($ - Base_of_code < %1) | |
times (%1 - ($ - Base_of_code)) db 0 | |
%endif | |
%endmacro | |
jmp short real_start | |
nop | |
db 'MSWIN4.1' | |
_org 5ah | |
fat_start dd 0 | |
data_start dd 0 | |
fat_secmask dw 0 | |
fat_secshift dw 0 | |
loadseg_off dw 0 | |
loadseg_seg dw 60h | |
;-------------------------------------- | |
real_start: | |
call PutRegs | |
mov ah, 0ch | |
int 18h | |
.kloop: ; press ESC to exit | |
mov ah, 0 | |
int 18h | |
cmp al, 1bh | |
jne .kloop | |
%ifdef TEST | |
jmp exit_test | |
%endif | |
;reboot: | |
cli | |
cld | |
xor ax, ax | |
mov ds, ax | |
mov es, ax | |
mov dx, [0486h] | |
jmp 0f000h:0fff0h | |
PutRegs: ; IP +22 | |
pushf ; +20 | |
push ax ; +18 | |
push dx ; +16 | |
push cx ; +14 | |
push bx ; +12 | |
push sp ; +10 | |
push bp ; +8 | |
push si ; +6 | |
push di ; +4 | |
push ds ; +2 | |
push es ; +0 | |
mov bp, sp | |
mov bx, .m_ax | |
call pmsg | |
mov ax, [bp + 18] | |
call ph16 | |
mov bx, .m_bx | |
call pmsg | |
mov ax, [bp + 12] | |
call ph16 | |
mov bx, .m_cx | |
call pmsg | |
mov ax, [bp + 14] | |
call ph16 | |
mov bx, .m_dx | |
call pmsg | |
mov ax, [bp + 16] | |
call ph16 | |
mov bx, .m_bp | |
call pmsg | |
mov ax, [bp + 8] | |
call ph16 | |
mov bx, .m_si | |
call pmsg | |
mov ax, [bp + 6] | |
call ph16 | |
mov bx, .m_di | |
call pmsg | |
mov ax, [bp + 4] | |
call ph16 | |
call put_nl | |
mov bx, .m_csip | |
call pmsg | |
mov ax, cs | |
call ph16 | |
mov al, ':' | |
call putc | |
mov ax, [bp + 22] | |
call ph16 | |
mov bx, .m_ds | |
call pmsg | |
mov ax, [bp + 2] | |
call ph16 | |
mov bx, .m_es | |
call pmsg | |
mov ax, [bp] | |
call ph16 | |
mov bx, .m_sssp | |
call pmsg | |
mov ax, ss | |
call ph16 | |
mov al, ':' | |
call putc | |
lea ax, [bp + 24] | |
call ph16 | |
mov bx, .m_flag | |
call pmsg | |
mov ax, [bp + 20] | |
call ph16 | |
call put_nl | |
pop es | |
pop ds | |
pop di | |
pop si | |
pop bp | |
pop bx ; drop sp | |
pop bx | |
pop cx | |
pop dx | |
pop ax | |
popf | |
ret | |
.m_ax db 'AX=', 0 | |
.m_bx db ' BX=', 0 | |
.m_cx db ' CX=', 0 | |
.m_dx db ' DX=', 0 | |
.m_bp db ' BP=', 0 | |
.m_si db ' SI=', 0 | |
.m_di db ' DI=', 0 | |
.m_csip db 'CS:IP=', 0 | |
.m_ds db ' DS=', 0 | |
.m_es db ' ES=', 0 | |
.m_sssp db ' SS:SP=', 0 | |
.m_flag db ' FLAGS=', 0 | |
putc: | |
push bx | |
push ds | |
.setvrseg: | |
lds bx, [cs: vram_off] | |
mov [bx], al | |
mov byte [bx + 2000h], 0e1h | |
add bx, byte 2 | |
mov [cs: vram_off], bx | |
pop ds | |
pop bx | |
ret | |
put_nl: | |
push ax | |
push cx | |
mov ax, [cs: vram_off] | |
mov cl, 80 * 2 | |
div cl | |
inc al | |
mul cl | |
mov [cs: vram_off], ax | |
pop cx | |
pop ax | |
ret | |
ph4: | |
and al, 0fh | |
add al, '0' | |
cmp al, '9' | |
jbe .l2 | |
add al, 'A' - '9' - 1 | |
.l2: | |
jmp short putc | |
ph8: | |
push ax | |
push ax | |
shr al, 1 | |
shr al, 1 | |
shr al, 1 | |
shr al, 1 | |
call ph4 | |
pop ax | |
call ph4 | |
pop ax | |
ret | |
ph16: | |
xchg ah, al | |
call ph8 | |
xchg ah, al | |
call ph8 | |
ret | |
pmsg: | |
push ax | |
.lp: | |
mov al, [cs: bx] | |
test al, al | |
jz .brk | |
call putc | |
inc bx | |
jmp short .lp | |
.brk: | |
pop ax | |
ret | |
vram_off: | |
dw 0 | |
vram_seg: | |
dw 0a000h | |
%ifndef TEST | |
_org 01fch | |
dw 0 | |
dw 0aa55h | |
%endif; !TEST | |
;====================================== | |
%ifdef TEST | |
segment .text | |
..start: | |
mov ax, 1011h | |
mov ds, ax | |
mov ax, 1213h | |
mov es, ax | |
mov bx, 0304h | |
mov cx, 0506h | |
mov dx, 0708h | |
mov bp, 090ah | |
mov si, 0b0ch | |
mov di, 0d0eh | |
mov ax, 0102h | |
jmp real_start | |
exit_test: | |
mov ax, 4c00h | |
int 21h | |
segment _STACK stack class=STACK | |
resw 256 | |
%endif | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment