LBPHacker

RTerm P2 tech demo

Jul 10th, 2016
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; In the convention I use DX and EX
  2. ; must be preserved accross function calls 
  3.    
  4. start:
  5.     mov bx, 0
  6.    
  7.     mov ax, .message0
  8.     call output_str
  9.    
  10.     mov ax, 0x0042
  11.     mov cx, .input_result
  12.     mov dx, 16       ; .input_result is 16 spaces and a 0
  13.     call input_str
  14.     mov [cx+ax], 0
  15.    
  16.     mov ax, .message1
  17.     call output_str
  18.     mov ax, cx
  19.     call output_str
  20.     mov ax, .message2
  21.     call output_str
  22.    
  23.     hlt
  24.  
  25. .message0: dw 0x1021, "Hello! What's your name?", 0
  26. .message1: dw 0x1081, "Hey there, ", 0x200F, 0
  27. .message2: dw 0x2007, ",", 0x10A1, "how is it going?", 0
  28. .input_result: dw "                ", 0
  29.  
  30. ; Input string
  31. ;  AX: initial position of the cursor
  32. ;  BX: port number
  33. ;  CX: pointer to input buffer
  34. ;  DX: maximum length of input
  35. ;  Clobbers: AX
  36. input_str:
  37.     push cx
  38.     push dx
  39.     or ax, 0x1000
  40.     push ax
  41.     mov dx, 0
  42.     send bx, ax
  43.     send bx, 0x5F
  44. .cloop:
  45.     recv ax, bx
  46.     cmp ax, 0x0A
  47.     je .done
  48.     cmp ax, 0x08
  49.     je .backspace
  50. .insert:
  51.     mov cx, [sp+1]
  52.     cmp dx, cx
  53.     je .cloop
  54.     mov cx, [sp]
  55.     add cx, dx
  56.     send bx, cx
  57.     send bx, ax
  58.     send bx, 0x5F
  59.     mov cx, [sp+2]
  60.     mov [dx+cx], ax
  61.     add dx, 1
  62.     jmp .cloop
  63. .backspace:
  64.     cmp dx, 0
  65.     je .cloop
  66.     mov ax, [sp]
  67.     sub dx, 1
  68.     add ax, dx
  69.     send bx, ax
  70.     send bx, 0x5F
  71.     send bx, 0x20
  72.     jmp .cloop
  73. .done:
  74.     pop ax
  75.     add ax, dx
  76.     send bx, ax
  77.     send bx, 0x20
  78.     mov ax, dx
  79.     pop dx
  80.     pop cx
  81.     ret
  82.    
  83. ; Output string
  84. ;  AX: pointer to null-terminated string
  85. ;  BX: port number
  86. ;  Clobbers: AX
  87. output_str:
  88.     push cx
  89. .cloop:
  90.     mov cx, [ax]
  91.     cmp cx, 0
  92.     je .done
  93.     send bx, cx
  94.     add ax, 1
  95.     jmp .cloop
  96. .done:
  97.     pop cx
  98.     ret
Add Comment
Please, Sign In to add comment