ponydos/shell.asm

150 lines
1.9 KiB
NASM

%include "ponydos.inc"
cpu 8086
bits 16
org 0
process_event:
push ax
push bx
push cx
push dx
push si
push di
push bp
push ds
push es
mov bp, cs
mov ds, bp
mov es, bp
cmp ax, WM_INITIALIZE
jne .not_initialize
call initialize
.not_initialize:
cmp ax, WM_PAINT
jne .not_paint
call paint
.not_paint:
pop es
pop ds
pop bp
pop di
pop si
pop dx
pop cx
pop bx
pop ax
retf
initialize:
; Set wallpaper
mov si, wallpaper_name
call PONYDOS_SEG:SYS_OPEN_FILE
mov bp, PONYDOS_SEG
mov es, bp
mov bx, GLOBAL_WALLPAPER
xor di, di ; read
call PONYDOS_SEG:SYS_MODIFY_SECTORS
; Put window 1 in the window chain
mov ax, cs
add ax, 0x001
xchg [es:GLOBAL_WINDOW_CHAIN_HEAD], ax
mov [next_window1], ax
; Put window 2 in the window chain
mov ax, cs
add ax, 0x002
xchg [es:GLOBAL_WINDOW_CHAIN_HEAD], ax
mov [next_window2], ax
ret
paint:
mov bp, cs
sub bx, bp
cmp bx, 0x001
je .window1
cmp bx, 0x002
je .window2
mov ax, bx
call hexprint16
call hang
.window1:
mov bx, [next_window1]
call forward_event
mov byte [window.number], '1'
; Draw a rectangle on-screen
mov bx, 8
mov cx, 8
mov dx, 4
mov si, window
mov di, 10
mov bp, 3
call PONYDOS_SEG:SYS_DRAW_RECT
ret
.window2:
mov bx, [next_window2]
call forward_event
mov byte [window.number], '2'
mov bx, 8
mov cx, 8
mov dx, 4
mov si, window
mov di, 14
mov bp, 4
call PONYDOS_SEG:SYS_DRAW_RECT
ret
; in:
; bx = window ID
; out:
; clobbers di
forward_event:
cmp bx, 0
je .end
push cs ; Return segment
mov di, .end
push di ; Return offset
mov di, 0xf000
and di, bx
push di ; Call segment
xor di, di
push di ; Call offset
retf
.end:
ret
next_window1 dw 0
next_window2 dw 0
wallpaper_name db 'wallpaper.bin', 0
%include "debug.inc"
window:
db 'W', 0x0f, 'i', 0x0f, 'n', 0x0f, 'd', 0x0f, 'o', 0x0f, 'w', 0x0f, ' ', 0x0f,
.number db '*', 0x0f
times 8 db ' ', 0xf0
times 8 db ' ', 0xf0
times 8 db ' ', 0xf0