Question

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
Was it helpful?

Solution

You just need to add a check when you're changing the position to make sure it hasn't moved off the edge. If it has, you set the position to the other side of the screen.

For example when moving left, you could do something like this:

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

You subtract 1 from the column position. Then you check if it is greater than or equal to 0. If it is, you're ok. If not, you set the column position to 79 (assuming the screen is 80 characters wide - you want to make a constant for that or look up that value).

You can do the same thing for all the other directions.

Strictly speaking you don't need the CMP COL,0 in the example above, since the SUB will set the appropriate flags anyway, but I think the code is clearer this way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top