我想在显示器上清除屏幕,但当我尝试时,总是屏幕被清除,但随后它会被放大,或者屏幕被清除,但我的光标消失了,我所有的代码细节都消失了
.model small
.stack 64
.data
welcome db "Welcome to Penang Travel Bus System!: $"
msg1 db 10,13, "Pick up destinations : $"
msg2 db 10,13, "Drop up destinations : $"
pickupTitle db 10,13, "---- Your Pickup Destination ---- $"
dropoffTitle db 10,13, "---- Your Drop-off Destination ---- $"
destination1 db 10,13, "1. Spice Arena Bayan Lepas $"
destination2 db 10,13, "2. Ayer Itam Bus Terminal $"
destination3 db 10,13, "3. Komtar Sentral Georgetown $"
destination4 db 10,13, "4. Balik Pulau Bus Terminal $"
destination5 db 10,13, "5. Gurney Plaza Pulau Tikus $"
destination6 db 10,13, "6. Vantage Point Bus Stop Tanjung Tokong $"
pickupPrompt db 10,13,10,13, "Enter the number of your pickup destination (1-6): $"
dropoffPrompt db 10,13,10,13, "Enter the number of your drop-off destination (1-6): $"
pickupChoice db ?
dropoffChoice db ?
pickupchosen db 10,13, "You selected pickup destination: $"
dropoffchosen db 10,13, "You selected drop-off destination: $"
invalid_pickup db 10,13, "Invalid pickup destination. Please select from (1-6): $"
invalid_dropoff db 10,13, "Invalid drop-off destination. Please select from(1-6): $"
invalid_destination db 10,13,"Your drop-off destination cannot be same as your pickup destination. Please select other destination: $"
invalid_quantity db 10,13, "Invalid quantity. Minimum number of tickets is 0 and maximum is 9. Please select from (1-9): $"
invalid_feature db 10,13, "Invalid feature. Enter from (1-4) or (0) for no features. $"
quantityPrompt db 10,13,10,13, "Enter the quantity of tickets (1-9): $"
ticketQuantity db ?
features db 10,13,10,13, "Would you like any of these extra features? $"
snacks db 10,13, "1. Snacks of your choice: (Twisties / Super Ring / Cheezels / Chips) - RM7.00 $"
beverages db 10,13, "2. Cold beverages (100Plus / Cola / 7UP / Sprite) - RM7.00 $"
entertainment db 10,13, "3. TV Entertainment (Smart TV) - RM10.00 $"
wifi db 10,13, "4. Onboard WiFi - RM8.00 $"
featuresPrompt db 10,13, "Enter the features you want (1-4) Press (0) if no : $"
featuresChoice db 0
featuremessage db 10,10, "Feature added. Would you like any more features? $"
chosenfeatures db 10,13, "Feature chosen: $"
;==========================================================================
.code
main proc far
mov ax , @data
mov ds , ax;
call clear_screen
mov ah , 09h
lea dx , welcome
int 21h
mov ah , 09h
lea dx , pickupTitle
int 21h
mov ah , 09h
lea dx , msg1
int 21h
mov ah , 09h
lea dx , destination1
int 21h
mov ah , 09h
lea dx , destination2
int 21h
mov ah , 09h
lea dx , destination3
int 21h
mov ah , 09h
lea dx , destination4
int 21h
mov ah , 09h
lea dx , destination5
int 21h
mov ah , 09h
lea dx , destination6
int 21h
mov ah , 09h
lea dx , pickupPrompt
int 21h
;Read user input for pickup choice
get_pickup:
mov ah , 01h ; Please prepare I want to read a char
int 21h
sub al , 30h ; Change it to integer
cmp al , 1
jl invalidpickup
cmp al , 6
jg invalidpickup
mov pickupChoice, al
jmp get_dropoff
invalidpickup: ; Display an invalid pickup message if user doesn't enter from 1 to 6
mov ah , 09h
lea dx , invalid_pickup
int 21h
jmp get_pickup
;Dropoff menu
get_dropoff:
mov ah , 09h
lea dx, dropoffTitle ; Display the title
int 21h
mov ah , 09h
lea dx, destination1 ; Display drop-off 1
int 21h
mov ah , 09h
lea dx , destination2 ; Display drop-off 2
int 21h
mov ah, 09h
lea dx , destination3 ; Display drop-off 3
int 21h
mov ah , 09h
lea dx , destination4 ; Display drop-off 4
int 21h
mov ah , 09h
lea dx , destination5 ; Display drop-off 5
int 21h
mov ah , 09h
lea dx , destination6 ; Display drop-off 6
int 21h
mov ah , 09h
lea dx , dropoffPrompt
int 21h
mov ah , 01h ; Please prepare I want to read a char
int 21h
sub al , 30h ; Change it to integer
cmp al , 1 ; If user doesn't enter (1-6) it shows an error message
jl invaliddropoff
cmp al , 6
jg invaliddropoff
mov dropoffChoice , al ; Protect the input
;We also need to check if the dropoff choice is the same as pickup
;Need to load to register to only use cmp
mov al , pickupChoice
cmp al , dropoffChoice
je invaliddestination
mov pickupChoice , al ; Move it back to the variable
jmp destination
invaliddropoff: ; Error message and loop back to get user input
mov ah , 09h
lea dx , invalid_dropoff
int 21h
jmp get_dropoff
invaliddestination: ; Error message if user enters same destination for pickup and dropoff
mov ah , 09h
lea dx , invalid_destination
int 21h
jmp get_dropoff
destination:
call clear_screen ; Clear the screen and then display the chosen destinations
int 10h
mov ah , 09h
lea dx , pickupchosen
int 21h
mov dl , pickupChoice
add dl , 30h
mov ah , 02h
int 21h
mov ah , 09h
lea dx , dropoffchosen
int 21h
mov dl , dropoffChoice
add dl , 30h
mov ah , 02h
int 21h
; Prompt for the quantity of tickets
mov al , 0 ; Clear the al register just in case
get_ticketquantity:
mov ah , 09h
lea dx , quantityPrompt
int 21h
; Read user input for quantity
mov ah , 01h
int 21h
sub al , 30h ; Change to integer
; Check if the quantity is valid (between 1 and 9)
cmp al , 1
jl invalidquantity
cmp al , 9
jg invalidquantity
mov ticketQuantity, al ; Protect the value
jmp extrafeatures
invalidquantity:
mov ah , 09h
lea dx, invalid_quantity ; Display error message for invalid quantity
int 21h
jmp get_ticketquantity ; Repeat the loop to get a valid quantity
extrafeatures:
;Code to display any extra features the user may input
mov ah , 09h
lea dx , features
int 21h
mov ah , 09h
lea dx , snacks
int 21h
mov ah , 09h
lea dx , beverages
int 21h
mov ah , 09h
lea dx , entertainment
int 21h
mov ah , 09h
lea dx , wifi
int 21h
mov ah , 09h
lea dx , featuresprompt
int 21h
mov ah , 01h
int 21h
sub al , 30h ; Protect the input
cmp al , 0
je displayfeatures ; Jump to displayfeatures if user enters 0
cmp al , 1
je addsnacks
cmp al , 2
je addbeverages
cmp al , 3
je addentertainment
cmp al , 4
je addwifi
jmp invalidfeature
addsnacks:
or featuresChoice, 1 ; If user chooses snacks, the corresponding bit is set (bit 1)
call clear_screen ; Clear screen and let user to choose anymore extra features
int 10h
mov ah , 09h
lea dx , featuremessage
int 21h
jmp extrafeatures
addbeverages:
or featuresChoice, 2 ; If user chooses beverages, the corresponding bit is set (bit 2)
call clear_screen ; Clear screen and let user to choose anymore extra features
int 10h
mov ah , 09h
lea dx , featuremessage
int 21h
jmp extrafeatures
addentertainment:
or featuresChoice, 4 ; If user chooses entertainment, the corresponding bit is set (bit 3)
call clear_screen ; Clear screen and let user to choose anymore extra features
int 10h
mov ah , 09h
lea dx , featuremessage
int 21h
jmp extrafeatures
addwifi:
or featuresChoice, 8 ; If user chooses wifi, the corresponding bit is set (bit 4)
call clear_screen ; Clear screen and let user to choose anymore extra features
int 10h
mov ah , 09h
lea dx , featuremessage
int 21h
jmp extrafeatures
invalidfeature:
cmp al , 1
jne validfeature ; If true , jump to valid feature option that
; repeats without showing invalid feature message
call clear_screen ; Clear screen and let user to choose anymore extra features
int 10h
mov ah , 09h ; If it didn't jump , this error message will appear
lea dx , invalid_feature
int 21h
jmp extrafeatures
validfeature: ; If the jump occured it will just loop back as normal
jmp extrafeatures
displayfeatures:
jmp finaldisplay ; Jump to final display
finaldisplay:
call clear_screen ; Clear screen and summarize the user order
int 10h
mov ah , 09h
lea dx , pickupchosen
int 21h
mov dl , pickupChoice
add dl , 30h
mov ah , 02h
int 21h
mov ah , 09h
lea dx , dropoffchosen
int 21h
mov dl , dropoffChoice
add dl , 30h
mov ah , 02h
int 21h
mov ah , 09h
lea dx , quantityPrompt
int 21h
mov dl , ticketQuantity
add dl , 30h
mov ah , 02h
int 21h
mov ah , 09h
lea dx , chosenfeatures
int 21h
; Check snacks
mov ah , 0
mov al , featuresChoice
and al , 1 ; Check the least significant bit (snacks)
cmp al , 1
je snacks_chosen
jmp beverages_check
snacks_chosen:
mov ah , 09h
lea dx , snacks
int 21h
jmp beverages_check
beverages_check:
; Check beverages (bit 1)
mov ah , 0
mov al , featuresChoice
and al , 2 ; Check bit 1 (beverages)
cmp al , 2
je beverages_chosen
jmp entertainment_check
beverages_chosen:
mov ah , 09h
lea dx , beverages
int 21h
jmp entertainment_check
entertainment_check:
; Check entertainment (bit 2)
mov ah , 0
mov al , featuresChoice
and al , 4 ; Check bit 2 (entertainment)
cmp al , 4
je entertainment_chosen
jmp wifi_check
entertainment_chosen:
mov ah , 09h
lea dx , entertainment
int 21h
jmp wifi_check
wifi_check:
; Check WiFi (bit 3)
mov ah , 0
mov al , featuresChoice
and al , 8 ; Check bit 3 (WiFi)
cmp al , 8
je wifi_chosen
jmp final
wifi_chosen:
mov ah , 09h
lea dx , wifi
int 21h
jmp final
final:
mov ax , 4c00h
int 21h
main endp
clear_screen:
mov ax,0b800h
mov es,ax
mov ax,0
mov di,ax
mov ax,160
mov si,ax
cld
mov cx,24*80
rep movsw
end main
我期待清晰的屏幕,然后移动到下一个显示器
1条答案
按热度按时间1sbrub3j1#
我认为问题出在最后一部分。这将从
ds:si
复制字节到es:di
,从ds:160
开始,并向上移动内存,因为方向标志已清除cld
。一些随机的字符和颜色出现在屏幕上。如果你想使用上面的代码,嗯,也许添加
clearBuffer dw 80*24 dup(0)
,然后从clearBuffer
复制字节到es:di (B800h)
。但这会增加项目规模。我认为更好的方法是复制立即值到vram。
REMOVE int 10h after every call to clear_screen
。这将消除屏幕上的大字母。UPDATE
好吧,我深入研究代码…
1.我添加了
set_cursor_0_0
以将光标设置为0,0坐标。每次用户输入后重置。以保持屏幕上的东西干净漂亮。1.背景为蓝色,前景为白色。
1.返回文本模式,将属性重置为正常。
1.下面是完整的代码