【问题标题】:Deleting a char on the screen删除屏幕上的字符
【发布时间】:2016-03-31 18:28:10
【问题描述】:

我正在为学校的一个项目使用 EMU8086 组装游戏。在这个游戏中,我需要允许用户输入一个字符串才能进行。当他输入字符串时,他可能会输入错误的内容并使用 backspace 进行更正。问题是 backspace 将光标移动到前一个字符上,但之前输入的字符仍然存在。为什么退格键不清除前一个字符?如何修复我的程序以删除屏幕上的前一个字符?

我的代码是:

data segment

ends

stack segment
dw   128  dup(0)
ends    
StringHelper db 20 dup(?)
Line db 13,10,'$'
FullInput db 'You cant type more than 20 letters!!! please try again!!',13,10,'$'
t db '$'
code segment
PROC PrintMessage
  ;BX MUST have OFFSET OF MESSAGE
  ; if you want to go down a line do (lea bx,line)      
  mov dx,bx      
  mov ah,09h
  int 21h     
  ret 
 endp printMessage
 proc InputString          
;askes the user to input chars untill he press (enter) then puts it in StringHelper
b:
lea bx, StringHelper
mov cx,5  
xor dx,dx
a:                 ;restarts string helper
mov [bx],00
inc bx
loop a
lea bx, StringHelper
up:
cmp dx,20        ;cheacks if you wrote more than 20 chars
jz TryAgain
deleted:
xor ax,ax
mov ah,01h
int 21h
xor ah,ah
mov cx,08h        ;checks if the user inputed the backspace key
cmp al,cl
jz BackSpace
mov cx,0dh
cmp al, cl                ;checks if the user enters enter
jz InputIsOver
inc dx
mov [bx],al
inc bx
jmp up
TryAgain:
lea bx, line
call PrintMessage 
lea bx, FullInput
call PrintMessage
jmp b:
BackSpace:
cmp dx,0            ;checks if te user didnt just BackSpaced nothing
jz deleted
lea bx,stringhelper  ;gets the start of the array
add bx,dx            ;adds dx which is the indexer to how many chars  you     already wrote
mov [bx],00h         ;puts 0(nothing) at that place
dec bx
dec dx
jmp deleted          ;returen to get an extra input
InPutIsOver:

ret
endp
start:
  mov  ax, @data
 mov  ds, ax
mov al,13h
int 10h 
call InputString
 ; add your code here

mov ax, 4c00h
int 21h  

ends

end start

【问题讨论】:

  • 如果你在单独的代码块之间留下空白行,那么那堵巨大的未缩进代码墙会更易读,诸如此类。至少 cmets 看起来是合理的(他们说为什么代码在做任何事情)。

标签: assembly backspace emu8086 x86-16


【解决方案1】:

对于典型的屏幕和终端仿真器,打印退格字符只会将光标向左移动一位。要清除字符,请尝试打印退格+空格+退格。

【讨论】:

    【解决方案2】:

    Keith 是正确的,即使在 DOS 中打印 backspace 字符也是非破坏性的。这意味着光标将返回,但下方的字符仍然存在。这是正常行为。

    我没有时间仔细查看代码,但在最初打印第一个 backspace 之后,您可以使用 Int 21h/Ah=2 打印出另一个 space 字符,然后另一个 退格

    在 Backspace 的代码中你有:

    BackSpace:
    cmp dx,0            ;checks if te user didnt just BackSpaced nothing
    jz deleted
    

    要修复它,我认为您可以将代码更改为:

    BackSpace:
    cmp dx,0            ;checks if te user didnt just BackSpaced nothing
    jz deleted
    
    mov ah, 02h         ; DOS Display character call 
    mov dl, 20h         ; A space to clear old character 
    int 21h             ; Display it  
    mov dl, 08h         ; Another backspace character to move cursor back again
    int 21h             ; Display it 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-08
      • 2019-08-29
      • 2015-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-15
      相关资源
      最近更新 更多