Advertisement
12Me21

R2 TEXT ADVENTURE ENGINE

Jun 15th, 2017
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. NAME r1,input
  2. NAME r3,port
  3. NAME r11,choices
  4. NAME r13,room
  5. NAME r14,sp
  6. NAME r15,ip
  7.  
  8. main:
  9.  
  10. ;setup
  11. MOV #sp,0
  12. MOV #room,game.start
  13. MOV #port,0
  14.  
  15. .loop:
  16.     ;READ ROOM INFO
  17.     MOV #choices,[#room] ;read the number of choices
  18.     ADD #choices,1 ;add 1 since it's easier to work with internally
  19.    
  20.     ;DISPLAY ROOM
  21.     SEND #port,0x3000 ;CLS
  22.     SEND #port,0x1000 ;LOCATE 0,0
  23.     SEND #port,0x200F ;COLOR white,black
  24.     ADD #room,#choices ;move past option data
  25.     CALL #room ;run code for the current room
  26.     SUB #room,#choices ;go back
  27.  
  28.     ;INPUT
  29.     SEND #port,0x1160 ;LOCATE 0,11
  30.     SEND #port,0x20E0 ;COLOR black,yellow
  31.     .getinput:
  32.         RECV #input,#port
  33.         JNC .getinput ;repeat until success
  34.         SUB #input,48 ;convert from ascii to number (0-9)
  35.         JBE .getinput ;if "0" or below
  36.         CMP #input,#choices ;compare with # of choices (+1)
  37.         JAE .getinput ;if > choices
  38.     ADD #input,48 ;convert back to ascii (this fails if input was <48 but we don't allow that anyway)
  39.     SEND #port,#input ;display character
  40.     SUB #input,48 ;actually we want a number (saving a register is worth 1 cycle, I think)
  41.    
  42.     MOV #room,[#room+#input] ;the location of the next room
  43. JMP .loop
  44.  
  45. game:
  46.  
  47. .start: ;room label
  48. dw 3 ;# of choices
  49. dw .one ;choice 1
  50. dw .two ;choice 2
  51. dw .three ;choice 3
  52. SEND #port,"enter 1, 2, or 3" ;code to run
  53. RET ;required
  54.  
  55. .one:
  56. dw 1
  57. dw .start
  58. SEND #port,"one"
  59. RET
  60.  
  61. .two:
  62. dw 1
  63. dw .start
  64. SEND #port,"two"
  65. RET
  66.  
  67. .three:
  68. dw 1
  69. dw .start
  70. SEND #port,"three"
  71. RET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement