Compare commits
2 Commits
00e08e8c0e
...
95d5901852
Author | SHA1 | Date |
---|---|---|
Juhani Krekelä | 95d5901852 | |
Juhani Krekelä | 0b46aa1336 |
181
edlin.asm
181
edlin.asm
|
@ -49,6 +49,18 @@ int_ctrl_break equ 0x23
|
|||
%macro addw 2
|
||||
db 0x03, 0xc0 + 8 * %1 + %2
|
||||
%endmacro
|
||||
%macro adcb 2
|
||||
db 0x12, 0xc0 + 8 * %1 + %2
|
||||
%endmacro
|
||||
%macro cmpw 2
|
||||
db 0x3b, 0xc0 + 8 * %1 + %2
|
||||
%endmacro
|
||||
%macro movw 2
|
||||
db 0x8b, 0xc0 + 8 * %1 + %2
|
||||
%endmacro
|
||||
%macro movb 2
|
||||
db 0x8a, 0xc0 + 8 * %1 + %2
|
||||
%endmacro
|
||||
%macro orw 2
|
||||
db 0x0b, 0xc0 + 8 * %1 + %2
|
||||
%endmacro
|
||||
|
@ -58,15 +70,12 @@ int_ctrl_break equ 0x23
|
|||
%macro subw 2
|
||||
db 0x2b, 0xc0 + 8 * %1 + %2
|
||||
%endmacro
|
||||
%macro subb 2
|
||||
db 0x2a, 0xc0 + 8 * %1 + %2
|
||||
%endmacro
|
||||
%macro xorw 2
|
||||
db 0x33, 0xc0 + 8 * %1 + %2
|
||||
%endmacro
|
||||
%macro cmpw 2
|
||||
db 0x3b, 0xc0 + 8 * %1 + %2
|
||||
%endmacro
|
||||
%macro movw 2
|
||||
db 0x8b, 0xc0 + 8 * %1 + %2
|
||||
%endmacro
|
||||
|
||||
; Sign extended byte to byte
|
||||
%macro cmpb_addr_ext 2
|
||||
|
@ -223,7 +232,7 @@ initialize_editor: ; 0240
|
|||
test byte [new_file_flag], 0xff
|
||||
jnz editor_mainloop
|
||||
|
||||
call __0370
|
||||
call command_a
|
||||
|
||||
editor_mainloop: ; 0273
|
||||
mov sp, stack.end
|
||||
|
@ -278,6 +287,8 @@ editor_mainloop: ; 0273
|
|||
repne scasb
|
||||
jne print_entry_error ; Not found
|
||||
|
||||
; CX counts down, so first entry matching gives cx=9, second cx=8, etc.
|
||||
|
||||
movw r_bx, r_cx
|
||||
mov ax, [__0a82]
|
||||
orw r_ax, r_ax
|
||||
|
@ -366,17 +377,19 @@ parse_line_specifier: ; 02f9
|
|||
ret
|
||||
|
||||
commands db 'QWASRDLIE', 13 ; 0340
|
||||
|
||||
; This is reversed in regards to commands table due to implementation of matching
|
||||
command_addresses: ; 034a
|
||||
dw command_q ; Q
|
||||
dw command_w ; W
|
||||
dw command_a ; A
|
||||
dw command_s ; S
|
||||
dw command_r ; R
|
||||
dw command_d ; D
|
||||
dw command_l ; L
|
||||
dw __0370 ; I
|
||||
dw command_e ; E
|
||||
dw command_cr ; CR
|
||||
dw command_e ; E
|
||||
dw command_i ; I
|
||||
dw command_l ; L
|
||||
dw command_d ; D
|
||||
dw command_r ; R
|
||||
dw command_s ; S
|
||||
dw command_a ; A
|
||||
dw command_w ; W
|
||||
dw command_q ; Q
|
||||
|
||||
find_file_end_char: ; 035e
|
||||
push di
|
||||
|
@ -397,7 +410,7 @@ find_file_end_char: ; 035e
|
|||
__036d:
|
||||
jmp print_eof_str
|
||||
|
||||
__0370:
|
||||
command_a:
|
||||
test byte [new_file_flag], 0xff
|
||||
jnz __036d
|
||||
|
||||
|
@ -487,7 +500,7 @@ __0406:
|
|||
_trampoline_oom_1: ; 0414
|
||||
jmp oom
|
||||
|
||||
command_e: ; 0417
|
||||
command_w: ; 0417
|
||||
db 0x8B, 0x1E, 0x80, 0x0A ; 0417 mov bx,[0xa80]
|
||||
db 0x0B, 0xDB ; 041B or bx,bx
|
||||
db 0x75, 0x1C ; 041D jnz 0x43b
|
||||
|
@ -557,51 +570,81 @@ db 0x42 ; 04AC inc dx
|
|||
db 0x3B, 0xDA ; 04AD cmp bx,dx
|
||||
db 0x75, 0xF7 ; 04AF jnz 0x4a8
|
||||
db 0xC3 ; 04B1 ret
|
||||
db 0x53 ; 04B2 push bx
|
||||
db 0xB0, 0x20 ; 04B3 mov al,0x20
|
||||
db 0xE8, 0x6C, 0x04 ; 04B5 call 0x924
|
||||
db 0xE8, 0x13, 0x00 ; 04B8 call 0x4ce
|
||||
db 0xB0, 0x3A ; 04BB mov al,0x3a
|
||||
db 0xE8, 0x64, 0x04 ; 04BD call 0x924
|
||||
db 0xB0, 0x2A ; 04C0 mov al,0x2a
|
||||
db 0x5B ; 04C2 pop bx
|
||||
db 0x3B, 0x1E, 0x90, 0x0A ; 04C3 cmp bx,[0xa90]
|
||||
db 0x74, 0x02 ; 04C7 jz 0x4cb
|
||||
db 0xB0, 0x20 ; 04C9 mov al,0x20
|
||||
db 0xE9, 0x56, 0x04 ; 04CB jmp 0x924
|
||||
db 0x33, 0xC0 ; 04CE xor ax,ax
|
||||
db 0x8A, 0xD0 ; 04D0 mov dl,al
|
||||
db 0xB9, 0x10, 0x00 ; 04D2 mov cx,0x10
|
||||
db 0xD1, 0xE3 ; 04D5 shl bx,1
|
||||
db 0x12, 0xC0 ; 04D7 adc al,al
|
||||
db 0x27 ; 04D9 daa
|
||||
db 0x86, 0xC4 ; 04DA xchg al,ah
|
||||
db 0x12, 0xC0 ; 04DC adc al,al
|
||||
db 0x27 ; 04DE daa
|
||||
db 0x86, 0xC4 ; 04DF xchg al,ah
|
||||
db 0x12, 0xD2 ; 04E1 adc dl,dl
|
||||
db 0xE2, 0xF0 ; 04E3 loop 0x4d5
|
||||
db 0xB3, 0x10 ; 04E5 mov bl,0x10
|
||||
db 0x92 ; 04E7 xchg ax,dx
|
||||
db 0xE8, 0x16, 0x00 ; 04E8 call 0x501
|
||||
db 0x8A, 0xC6 ; 04EB mov al,dh
|
||||
db 0xE8, 0x02, 0x00 ; 04ED call 0x4f2
|
||||
db 0x8A, 0xC2 ; 04F0 mov al,dl
|
||||
db 0x8A, 0xF0 ; 04F2 mov dh,al
|
||||
db 0xD0, 0xE8 ; 04F4 shr al,1
|
||||
db 0xD0, 0xE8 ; 04F6 shr al,1
|
||||
db 0xD0, 0xE8 ; 04F8 shr al,1
|
||||
db 0xD0, 0xE8 ; 04FA shr al,1
|
||||
db 0xE8, 0x02, 0x00 ; 04FC call 0x501
|
||||
db 0x8A, 0xC6 ; 04FF mov al,dh
|
||||
db 0x24, 0x0F ; 0501 and al,0xf
|
||||
db 0x74, 0x02 ; 0503 jz 0x507
|
||||
db 0xB3, 0x00 ; 0505 mov bl,0x0
|
||||
db 0x04, 0x30 ; 0507 add al,0x30
|
||||
db 0x2A, 0xC3 ; 0509 sub al,bl
|
||||
db 0xE9, 0x16, 0x04 ; 050B jmp 0x924
|
||||
|
||||
command_s: ; 050e
|
||||
print_line_prefix: ; 04b2
|
||||
push bx
|
||||
|
||||
mov al, ' '
|
||||
call print_char
|
||||
call print_number
|
||||
mov al, ':'
|
||||
call print_char
|
||||
mov al, '*'
|
||||
|
||||
pop bx
|
||||
|
||||
cmp bx, [current_line]
|
||||
je .end
|
||||
mov al, ' '
|
||||
|
||||
.end: jmp print_char
|
||||
|
||||
print_number: ; 04ce
|
||||
; Input in bx
|
||||
|
||||
; Zero out the 5-digit BCD number
|
||||
xorw r_ax, r_ax
|
||||
movb r_dl, r_al
|
||||
|
||||
mov cx, 16
|
||||
.loop: ; 04d5
|
||||
shl bx, 1
|
||||
|
||||
; Double al (bcd), and add in carry out from the shift
|
||||
adcb r_al, r_al
|
||||
daa
|
||||
; Double ah (bcd) and propagate carry
|
||||
xchg al, ah
|
||||
adcb r_al, r_al
|
||||
daa
|
||||
xchg al, ah
|
||||
; Double dl (bcd) and propagate carry
|
||||
adcb r_dl, r_dl
|
||||
|
||||
loop .loop
|
||||
|
||||
print_bcd:
|
||||
; Prints a 5-digit BCD number stored in DX:AX as such (x is ignored)
|
||||
; dh dl ah al
|
||||
; xx x1 23 45
|
||||
mov bl, '0' - ' ' ; If value is zero, replace with space
|
||||
|
||||
xchg ax, dx
|
||||
; First digit, low nybble of dl
|
||||
call print_bcd_digit
|
||||
; Next two digits, ah
|
||||
movb r_al, r_dh
|
||||
call print_bcd_byte
|
||||
; Final two digits, al
|
||||
movb r_al, r_dl
|
||||
|
||||
print_bcd_byte: ; 04f2
|
||||
movb r_dh, r_al
|
||||
times 4 shr al, 1
|
||||
call print_bcd_digit
|
||||
movb r_al, r_dh
|
||||
|
||||
print_bcd_digit: ; 0501
|
||||
and al, 0xf
|
||||
jz .to_ascii
|
||||
mov bl, 0 ; Only apply replacement to zero values
|
||||
|
||||
.to_ascii:
|
||||
add al, '0'
|
||||
subb r_al, r_bl
|
||||
jmp print_char
|
||||
|
||||
command_l: ; 050e
|
||||
db 0x8B, 0x1E, 0x80, 0x0A ; 050E mov bx,[0xa80]
|
||||
db 0x0B, 0xDB ; 0512 or bx,bx
|
||||
db 0x75, 0x0C ; 0514 jnz 0x522
|
||||
|
@ -668,7 +711,7 @@ db 0xAA ; 0591 stosb
|
|||
db 0xC3 ; 0592 ret
|
||||
db 0xE9, 0xC9, 0x00 ; 0593 jmp 0x65f
|
||||
|
||||
command_d: ; 0596
|
||||
command_r: ; 0596
|
||||
db 0xE8, 0xFD, 0x00 ; 0596 call 0x696
|
||||
db 0x75, 0xF8 ; 0599 jnz 0x593
|
||||
db 0x8B, 0x36, 0x8C, 0x0A ; 059B mov si,[0xa8c]
|
||||
|
@ -725,7 +768,7 @@ db 0xC3 ; 0621 ret
|
|||
db 0xBA, 0x21, 0x0A ; 0622 mov dx,0xa21
|
||||
db 0xEB, 0x3B ; 0625 jmp short 0x662
|
||||
|
||||
command_l: ; 0627
|
||||
command_s: ; 0627
|
||||
db 0xE8, 0x6C, 0x00 ; 0627 call 0x696
|
||||
db 0x75, 0x33 ; 062A jnz 0x65f
|
||||
db 0x8B, 0x1E, 0x8A, 0x0A ; 062C mov bx,[0xa8a]
|
||||
|
@ -841,7 +884,7 @@ db 0xAA ; 074A stosb
|
|||
db 0x41 ; 074B inc cx
|
||||
db 0xEB, 0xF3 ; 074C jmp short 0x741
|
||||
|
||||
command_r: ; 074e
|
||||
command_d: ; 074e
|
||||
db 0x8B, 0x1E, 0x80, 0x0A ; 074E mov bx,[0xa80]
|
||||
db 0x0B, 0xDB ; 0752 or bx,bx
|
||||
db 0x75, 0x04 ; 0754 jnz 0x75a
|
||||
|
@ -866,7 +909,7 @@ db 0x33, 0xC9 ; 077E xor cx,cx
|
|||
db 0xEB, 0x55 ; 0780 jmp short 0x7d7
|
||||
db 0xE9, 0x6A, 0xFB ; 0782 jmp 0x2ef
|
||||
|
||||
command_q: ; 0785
|
||||
command_cr: ; 0785
|
||||
db 0x8B, 0x1E, 0x80, 0x0A ; 0785 mov bx,[0xa80]
|
||||
db 0x0B, 0xDB ; 0789 or bx,bx
|
||||
db 0x75, 0x05 ; 078B jnz 0x792
|
||||
|
@ -931,7 +974,7 @@ oom: ; 080c
|
|||
int 0x21
|
||||
jmp editor_mainloop
|
||||
|
||||
command_a: ; 08cd
|
||||
command_i: ; 0816
|
||||
db 0xB8, 0x23, 0x25 ; 0816 mov ax,0x2523
|
||||
db 0xBA, 0x7D, 0x08 ; 0819 mov dx,0x87d
|
||||
db 0xCD, 0x21 ; 081C int 0x21
|
||||
|
@ -994,7 +1037,7 @@ db 0x4F ; 089E dec di
|
|||
db 0x89, 0x3E, 0x9A, 0x0A ; 089F mov [0xa9a],di
|
||||
db 0xE9, 0xCD, 0xF9 ; 08A3 jmp 0x273
|
||||
|
||||
command_cr: ; 08a6
|
||||
command_q: ; 08a6
|
||||
db 0xBA, 0x45, 0x0A ; 08A6 mov dx,0xa45
|
||||
db 0xB4, 0x09 ; 08A9 mov ah,0x9
|
||||
db 0xCD, 0x21 ; 08AB int 0x21
|
||||
|
@ -1012,7 +1055,7 @@ db 0xCD, 0x20 ; 08C2 int 0x20
|
|||
db 0xC7, 0x06, 0x80, 0x0A, 0xFF, 0xFF ; 08C4 mov word [0xa80],0xffff
|
||||
db 0xE8, 0xA3, 0xFA ; 08CA call 0x370
|
||||
|
||||
command_w: ; 08cd
|
||||
command_e: ; 08cd
|
||||
db 0xC6, 0x06, 0x7F, 0x0A, 0x01 ; 08CD mov byte [0xa7f],0x1
|
||||
db 0xBB, 0xFF, 0xFF ; 08D2 mov bx,0xffff
|
||||
db 0xE8, 0x63, 0xFB ; 08D5 call 0x43b
|
||||
|
|
Loading…
Reference in New Issue