-2

Using BIOS video interrupts, I can finally move my cursor around the screen but when it reaches the end of the screen it disappears. I need for it to appear on the other side, I mean if it goes straight to the ride side it will come out to the left side of the screen. Can someone give me an idea how to do this?

  .MODEL SMALL
  .STACK 1000h
  .DATA

  ROW DB 12 ; initial cursor position
  COL DB 40

 .CODE
 .STARTUP
START :
  MOV AH, 0     ; set video mode
  MOV AL, 3     ; 80x25 color
  INT 10H           ; video BIOS call   
  MOV AH, 2     ; set cursor position
  MOV BH, 0     ; display page number
  MOV DH, 24        ; set bottom row number
  MOV DL, 7     ; column number
  INT 10H           ; video BIOS call
  MOV AH,2        ;set cursor position
 MOV BH,0        ;display page number
 MOV DH,ROW      ;row number
 MOV DL,COL      ;column number
 INT 10H         ;video BIOS call
 MOV BL, 15
 INT 10H         ;video BIOS call

READ :
MOV AH, 0       ;read keyboard
INT 16h           ;BIOS call
CMP AL,0
JZ CSC
CMP AL,'q'
JMP EXIT

CSC :
CMP   AH,72        
JZ   UP
CMP   AH,80       
JZ   DOWN
CMP   AH,75       
JZ   LEFT
CMP   AH,77        
JZ   RIGHT

 UP:
SUB ROW, 1
MOV   AH,2          ;set cursor position
MOV   BH,0          ;display page number
MOV   DH,ROW        ;row number
MOV   DL,COL        ;column number
INT   10H           ;video BIOS call
JMP READ      

 DOWN:
ADD   ROW, 1
MOV   AH,2          ;set cursor position
MOV   BH,0          ;display page number
MOV   DH,ROW        ;row number
MOV   DL,COL        ;column number
INT   10H           ;video BIOS call
JMP   READ   

 RIGHT:
ADD   COL, 1
MOV   AH,2          ;set cursor position
MOV   BH,0          ;display page number
MOV   DH,ROW        ;row number
MOV   DL,COL        ;column number
INT   10H           ;video BIOS call
JMP   READ   

LEFT:
SUB   COL, 1
MOV   AH,2          ;set cursor position
MOV   BH,0          ;display page number
MOV   DH,ROW        ;row number
MOV   DL,COL        ;column number
INT   10H           ;video BIOS call
JMP   READ      
EXIT : .EXIT 
END
4

1 回答 1

1

您只需要在更改位置时添加一个检查,以确保它没有移出边缘。如果有,则将位置设置到屏幕的另一侧。

例如,当向左移动时,您可以执行以下操作:

LEFT:
SUB   COL, 1
CMP   COL, 0
JGE   LEFTOK:
MOV   COL, 79
LEFTOK:

您从列位置中减去 1。然后你检查它是否大于或等于0。如果是,你就可以了。如果不是,则将列位置设置为 79(假设屏幕为 80 个字符宽 - 您想为此创建一个常量或查找该值)。

您可以对所有其他方向执行相同的操作。

严格来说,您不需要CMP COL,0上面示例中的 ,因为SUB无论如何都会设置适当的标志,但我认为这样代码更清晰。

于 2013-07-18T21:26:59.063 回答