262 lines
4.8 KiB
ArmAsm
262 lines
4.8 KiB
ArmAsm
.arch i8086,jumps
|
|
.code16
|
|
.intel_syntax noprefix
|
|
|
|
.section .init
|
|
.global _start
|
|
_start:
|
|
mov ax, cs
|
|
mov ds, ax
|
|
mov es, ax
|
|
cli
|
|
mov ss, ax
|
|
mov sp, 0x100
|
|
sti
|
|
jmp main
|
|
|
|
.section .bss
|
|
kBufSize = 77
|
|
kDividerRow = 23
|
|
kRecvBufSize = 128
|
|
|
|
curpos: .word 0
|
|
inputsize: .byte 0
|
|
escaped: .byte 0
|
|
inputbuf: .zero kBufSize
|
|
recvbuf: .zero kRecvBufSize
|
|
|
|
# XXX: funky call
|
|
# inputs:
|
|
# si: string offset
|
|
# cl: string length
|
|
# clobbers: ax, bh, dx
|
|
.section .text.printn
|
|
printn:
|
|
push bx
|
|
push bp
|
|
mov bh, 0
|
|
1:
|
|
test cl, cl
|
|
jz 0f
|
|
mov al, [si]
|
|
cmpb escaped, 0
|
|
je 3f
|
|
cmp al, 'm'
|
|
jne 5f
|
|
movb escaped, 0
|
|
jmp 5f
|
|
3:
|
|
cmp al, 0x1b # ESC
|
|
jne 4f
|
|
movb escaped, 1
|
|
jmp 5f
|
|
4:
|
|
mov ah, 0x0e # write tty
|
|
int 0x10
|
|
push cx
|
|
mov ah, 0x03 # get cursor
|
|
int 0x10
|
|
cmp dh, kDividerRow
|
|
jb 2f
|
|
push dx
|
|
mov ah, 0x08 # read color
|
|
int 0x10
|
|
mov bh, ah
|
|
xor cx, cx
|
|
mov dx, 0x164f
|
|
mov ax, 0x0601 # scroll up, 1 line
|
|
int 0x10
|
|
pop dx
|
|
dec dh
|
|
mov bh, 0
|
|
mov ah, 0x02 # set cursor
|
|
int 0x10
|
|
2:
|
|
pop cx
|
|
5:
|
|
inc si
|
|
dec cl
|
|
jmp 1b
|
|
0:
|
|
pop bp
|
|
pop bx
|
|
ret
|
|
|
|
# XXX: funky call
|
|
# inputs:
|
|
# si: string offset
|
|
# cl: string length
|
|
# clobbers: ax, bh, dx
|
|
.section .text.addtext
|
|
addtext:
|
|
push di
|
|
push cx
|
|
mov bh, 0
|
|
mov ah, 0x03 # get cursor pos
|
|
int 0x10
|
|
pop cx
|
|
push dx
|
|
mov di, offset curpos
|
|
mov dx, [di]
|
|
mov ah, 0x02 # set cursor
|
|
int 0x10
|
|
call printn
|
|
mov ah, 0x03 # get cursor pos
|
|
int 0x10
|
|
mov [di], dx
|
|
pop dx
|
|
mov ah, 0x02 # set cursor
|
|
int 0x10
|
|
pop di
|
|
ret
|
|
|
|
.section .text.sendbuffer
|
|
sendbuffer:
|
|
push bp
|
|
mov bp, sp
|
|
sub sp, 2
|
|
mov al, inputsize
|
|
mov [bp-2], al
|
|
movb inputsize, 0
|
|
mov si, offset .l0
|
|
mov cl, 2
|
|
call addtext
|
|
mov si, offset inputbuf
|
|
mov cl, [bp-2]
|
|
call addtext
|
|
mov si, offset .l1
|
|
mov cl, 2
|
|
call addtext
|
|
mov si, offset inputbuf
|
|
mov cl, [bp-2]
|
|
call parasend
|
|
# XXX: should check cx in case not everything was sent
|
|
mov al, ' '
|
|
mov dx, 0x1802 # [24; 2]
|
|
call drawchar
|
|
mov ah, 0x02
|
|
int 0x10 # mov cursor back to start of line
|
|
add sp, 2
|
|
pop bp
|
|
ret
|
|
|
|
# draw until end of line
|
|
# al: char
|
|
# dh: row
|
|
# dl: start col
|
|
.section .text.drawchar
|
|
drawchar:
|
|
push ax
|
|
mov bh, 0
|
|
mov ah, 0x02 # set cursor
|
|
int 0x10
|
|
mov cx, 80
|
|
sub cl, dl
|
|
pop ax
|
|
mov ah, 0x0a
|
|
int 0x10
|
|
ret
|
|
|
|
.section .text.parasend
|
|
parasend:
|
|
mov ah, 0x06 # send parallel
|
|
push cx
|
|
push si
|
|
int 0x80
|
|
mov cx, 1
|
|
push cx
|
|
mov cx, offset .l1 + 1
|
|
push cx
|
|
mov ah, 0x06 # send parallel
|
|
int 0x80
|
|
add sp, 8
|
|
ret
|
|
|
|
prompt:
|
|
mov bh, 0
|
|
mov dx, 0x1800
|
|
mov ah, 0x02
|
|
int 0x10
|
|
mov ah, 0x0e
|
|
mov al, '>'
|
|
int 0x10
|
|
mov ah, 0x0e
|
|
mov al, ' '
|
|
int 0x10
|
|
ret
|
|
|
|
.section .rodata
|
|
.l0: .ascii "> "
|
|
.l1: .byte 0x0d, 0x0a
|
|
.l2: .ascii "MUSHRoom 8086 client 0.1\r\n"
|
|
l2len = . - offset .l2
|
|
|
|
.section .text.main
|
|
.global main
|
|
main:
|
|
movb inputsize, 0 # inputsize = 0
|
|
movw curpos, 0 # mov buffer cursor to [0;0]
|
|
movb escaped, 0
|
|
mov ax, 0x0002
|
|
int 0x10
|
|
mov si, offset .l2
|
|
mov cl, l2len
|
|
call addtext
|
|
mov dx, 0x1700 # [23; 0]
|
|
mov al, 0xc4 # horizontal box line
|
|
call drawchar
|
|
call prompt
|
|
0:
|
|
mov ah, 0x01
|
|
int 0x16 # check buffer
|
|
jz 1f # if empty, do a round of comms
|
|
mov ah, 0x00
|
|
int 0x16 # read 1 key
|
|
cmp al, 0x08 # backspace
|
|
je 5f
|
|
cmp al, 0x0d # CR
|
|
je 4f
|
|
mov di, offset inputbuf
|
|
mov si, offset inputsize
|
|
mov bh, 0
|
|
mov bl, [si]
|
|
cmp bl, kBufSize # stop accepting input at end of screen
|
|
jge 1f # do a round of comms
|
|
mov [di+bx], al # store character in buffer
|
|
incb [si] # increment buffer size
|
|
mov ah, 0x0e
|
|
mov bh, 0
|
|
int 0x10 # local echo
|
|
jmp 0b
|
|
5:
|
|
mov bl, inputsize
|
|
test bl, bl
|
|
jz 0b
|
|
decb inputsize
|
|
mov bh, 0
|
|
mov ah, 0x0e
|
|
int 0x10 # backspace
|
|
mov ax, 0x0e20
|
|
int 0x10
|
|
mov ax, 0x0e08
|
|
int 0x10
|
|
jmp 0b
|
|
4:
|
|
call sendbuffer # send input buffer
|
|
1:
|
|
mov ah, 0x07 # do parallel comms
|
|
int 0x80
|
|
mov ax, kRecvBufSize
|
|
push ax
|
|
mov ax, offset recvbuf
|
|
push ax
|
|
mov ah, 0x05 # recv
|
|
int 0x80
|
|
test al, al
|
|
mov cl, al
|
|
pop si
|
|
pop bx
|
|
jz 0b
|
|
call addtext
|
|
jmp 0b
|