###########
# MikeMon #
###########

##############
# MEMORY MAP #
##############

# ADDR		WR						RD
# 0xFFE 	HDMI_Y_SIZE				HDMI_Y_SIZE
# 0xFFD     HDMI_X_SIZE				HDMI_X_SIZE
# 0xFFC 	HDMI_COLOUR				HDMI_COLOUR
# 0xFFB     HDMI_TILE				HDMI_TILE
# 0xFFA 	HDMI_Y_POS				HDMI_Y_POS
# 0xFF9     HDMI_X_POS				HDMI_X_POS
# 0xFF8 	HDMI_COMMAND			HDMI_COMMAND
# 0xFF8     HDMI_STATUS				HDMI_STATUS
# 0xFF7     GPO				        GPO
# 0xFF6 	GPO			            GPI
# 0xFF5     UART TX DATA			UART RX DATA
# 0xFF4     UART TX DATA			UART STATUS 

# 0xFF3     MEM	RAM					RAM
# ...		...						...
# 0x000		MEM	RAM					RAM

##################
# UART REGISTERS #
##################

# TX : B7 - B0 data
# RX : B7 - B0 data 

# STATUS REGISTER VERSION-A
# -------------------------
# B7 : NU
# B6 : NU
# B5 : NU
# B4 : NU
# B3 : NU
# B2 : TX Idle
# B1 : RX Idle
# B0 : RX Valid

# STATUS REGISTER VERSION-B
# -------------------------
# B7: NU (0)
# B6: NU (0)
# B5: TX Idle
# B4: TX FIFO Full
# B3: TX FIFO Empty
# B2: RX Idle
# B1: RX FIFO Full
# B0: RX FIFO Empty

###############
# ASCII CODES #
###############

# Dec Hex Char                           Dec Hex Char      Dec Hex Char     Dec Hex Char
# ------------                           ------------      ------------     ------------
#  0  00  NUL (null)                      32  20  SPACE     64  40  @        96   60  `
#  1  01  SOH (start of heading)          33  21  !         65  41  A        97   61  a
#  2  02  STX (start of text)             34  22  "         66  42  B        98   62  b
#  3  03  ETX (end of text)               35  23  #         67  43  C        99   63  c
#  4  04  EOT (end of transmission)       36  24  $         68  44  D        100  64  d
#  5  05  ENQ (enquiry)                   37  25  %         69  45  E        101  65  e
#  6  06  ACK (acknowledge)               38  26  &         70  46  F        102  66  f
#  7  07  BEL (bell)                      39  27  '         71  47  G        103  67  g
#  8  08  BS  (backspace)                 40  28  (         72  48  H        104  68  h
#  9  09  TAB (horizontal tab)            41  29  )         73  49  I        105  69  i
# 10  0A  LF  (NL line feed, new line)    42  2A  *         74  4A  J        106  6A  j
# 11  0B  VT  (vertical tab)              43  2B  +         75  4B  K        107  6B  k
# 12  0C  FF  (NP form feed, new page)    44  2C  ,         76  4C  L        108  6C  l
# 13  0D  CR  (carriage return)           45  2D  -         77  4D  M        109  6D  m
# 14  0E  SO  (shift out)                 46  2E  .         78  4E  N        110  6E  n
# 15  0F  SI  (shift in)                  47  2F  /         79  4F  O        111  6F  o
# 16  10  DLE (data link escape)          48  30  0         80  50  P        112  70  p
# 17  11  DC1 (device control 1)          49  31  1         81  51  Q        113  71  q
# 18  12  DC2 (device control 2)          50  32  2         82  52  R        114  72  r
# 19  13  DC3 (device control 3)          51  33  3         83  53  S        115  73  s
# 20  14  DC4 (device control 4)          52  34  4         84  54  T        116  74  t
# 21  15  NAK (negative acknowledge)      53  35  5         85  55  U        117  75  u
# 22  16  SYN (synchronous idle)          54  36  6         86  56  V        118  76  v
# 23  17  ETB (end of trans. block)       55  37  7         87  57  W        119  77  w
# 24  18  CAN (cancel)                    56  38  8         88  58  X        120  78  x
# 25  19  EM  (end of medium)             57  39  9         89  59  Y        121  79  y
# 26  1A  SUB (substitute)                58  3A  :         90  5A  Z        122  7A  z
# 27  1B  ESC (escape)                    59  3B  ;         91  5B  [        123  7B  {
# 28  1C  FS  (file separator)            60  3C  <         92  5C  \        124  7C  |
# 29  1D  GS  (group separator)           61  3D  =         93  5D  ]        125  7D  }
# 30  1E  RS  (record separator)          62  3E  >         94  5E  ^        126  7E  ~
# 31  1F  US  (unit separator)            63  3F  ?         95  5F  _        127  7F  DEL

#####################
# TERMINAL COMMANDS #
#####################

# Common serial port speeds 
# Bit rate (bit/s)  Time per bit (μs)  Common applications 
# ----------------  -----------------  -------------------
# 75 	            13333.3 	 	
# 110 	            9090.9 	     	   Bell 101 modem
# 134.5 	        7434.9 	  	
# 150 	            6666.6 	 	
# 300 	            3333.3 	       	   Bell 103 modem or V.21 modem
# 600 	            1666.7 	  	
# 1,200 	        833.3 	  	       Bell 202, Bell 212A, or V.22 modem
# 1,800 	        555.6 	  	
# 2,400 	        416.7 	  	       V.22bis modem
# 4,800 	        208.3 	     	   V.27ter modem
# 7,200 	        138.9 	  	
# 9,600 	        104.2 	  	       V.32 modem
# 14,400 	        69.4 	     	   V.32bis modem
# 19,200 	        52.1 	  	
# 31,250 	        32 	  	           MIDI port
# 38,400 	        26.0 	  	
# 56,000 	        17.9 	  	       V.90/V.92 modem
# 57,600 	        17.4 	  	       V.32bis modem with V.42bis compression   ****
# 76,800 	        13.0 	  	       BACnet MS/TP networks[20]
# 115,200 	        8.68 	  	       V.34 modem with V.42bis compression, 
#                                      low cost serial V.90/V.92 modem with V.42bis or V.44 compression 
# screen /dev/ttyS0 19200,cs8
# screen /dev/ttyUSB0 57600

# Screen Command 	  Task
# --------------      ----
# Ctrl+a c 	          Create new window
# Ctrl+a k 	          Kill the current window / session
# Ctrl+a w            List all windows
# Ctrl+a 0-9 	      Go to a window numbered 0 9, use Ctrl+a w to see number
# Ctrl+a Ctrl+a 	  Toggle / switch between the current and previous window
# Ctrl+a S 	          Split terminal horizontally into regions and press Ctrl+a c to create new window there
# Ctrl+a :resize 	  Resize region
# Ctrl+a :fit 	      Fit screen size to new terminal size. You can also hit Ctrl+a F for the the same task
# Ctrl+a :remove 	  Remove / delete region. You can also hit Ctrl+a X for the same taks
# Ctrl+a tab 	      Move to next region
# Ctrl+a D (Shift-d)  Power detach and logout
# Ctrl+a d 	          Detach but keep shell window open
# Ctrl-a Ctrl-\ 	  Quit screen
# Ctrl-a ? 	          Display help screen i.e. display a list of commands
# Backspace allowed to delete entered char, but display is not updated
# Escape restarts

# Monitor Commands
# ----------------

# Read examples    
# 4F
# .55
# 4F 52 56
# 4F.5F
# 4F.52 56 58.5A

# Write examples
# 30:A0
# :A1 A2 A3 A4 A5
# 30:A0 A1 A2 A3 A4 A5

# Run
# 100 R

# Main Program
# ------------

start:
  move ra 0
  store ra rx_buffer_rd_index
  store ra rx_buffer_wr_index
  store ra tx_buffer_rd_index
  store ra tx_buffer_wr_index
  store ra address

  load ra welcome_address          # display welcome message
  store ra string_pointer
  call uart_tx_string

restart:
  move ra 0  			           # reset buffer index
  store ra mode
  store ra current_command
		           
  call uart_tx_prompt              # display prompt "\"

# 7F  DEL   0
# 0D  CR   6
# 1B  ESC  13

rx_CHAR:
  call uart_rx                    
  cmp ra 0xFF                      # test if CHAR valid
  jumpz tx_CHAR                    # not valid, transmit buffered char

  cmp ra 0x7F			           # DEL?
  jumpnz rx_CHAR_test_cr         

  load ra rx_buffer_wr_index       # yes, is RX buffer empty?
  subm ra rx_buffer_rd_index       # 
  jumpz tx_CHAR                    # yes, skip 

  load ra rx_buffer_wr_index       # decrement rx_buffer_wr_index      
  sub ra 1
  and ra 0x3F
  store ra rx_buffer_wr_index
  jump tx_CHAR

rx_CHAR_test_cr:  
  cmp ra 0x0D			           # CR?
  jumpnz rx_CHAR_test_esc  

  call uart_tx_lf
  call uart_tx_cr

  jump process_BUF                 # yes, process buffer

rx_CHAR_test_esc:
  cmp ra 0x1B			           # ESC?
  jumpz start                      # yes, error start

rx_CHAR_test_line_feed:
  cmp ra 0x0A			           # LF?
  jumpz tx_CHAR                    # yes, ignore

rx_CHAR_buffer:
  call rx_buffer_write             # write RX char to RX buffer
  cmp ra 0xFF
  jumpz start                      # error, rx buffer was full

  call tx_buffer_write             # echo char, write RX char to TX buffer
  cmp ra 0xFF
  jumpz start                      # error, rx buffer was full

tx_CHAR:
  call uart_tx_ready               # is uart TX ready
  cmp ra 0xFF
  jumpz rx_CHAR                    # no, skip

  call tx_buffer_read
  cmp ra 0xFF                      # is there data to TX
  jumpz rx_CHAR                    # no, skip
  call uart_tx
  jump rx_CHAR

process_BUF:
  move rc 0			               # rc = address 			
  move rd 0                        # rd = digit count
  load ra current_command     
  store ra previous_command        # log command to detect duplicates
   
digit_loop: 
  call rx_buffer_read              # read char from RX buffer
  cmp ra 0xFF                      # is buffer empty?          
  jumpz digit_process_exit         # yes, process digit

digit_process:
  call test_digit                  # is char a hex digit
  cmp ra 0xFF                    
  jumpz decode_CMD	               # not a digit, decode
         
  asl rc                           # move hex digit up
  asl rc
  asl rc
  asl rc
  add rc ra                        # add new digit
  add rd 1                         # increment number digit count

  jump digit_loop                  # repeat

digit_process_exit:
  and rd 0xFF                      # yes, have digits been enter?
  jumpnz decode_NUM                # yes, decode
  jump restart                     # no digits entered restart

decode_NUM:
  # 0 = read
  # 1 = multi read
  # 2 = write
  # 3 = multi write

  load ra mode
  sub ra 1
  jumpz decode_NUM_multiple_read
  sub ra 1
  jumpz decode_NUM_single_write
  sub ra 1
  jumpz decode_NUM_multiple_write

decode_NUM_single_read: 
  move ra rc			           # save generated address
  store ra address

  call uart_tx_hex                 # text data
  call uart_tx_colon               # tx address
  call uart_tx_space

  load ra address
  load ra (ra)                     # read data at address
  call uart_tx_hex                 # text data

  move ra 0
  store ra current_command   

  call uart_tx_lf
  call uart_tx_cr       
  jump process_BUF                 # continue

decode_NUM_multiple_read:
  move ra rc			           # save generated address
  store ra max_address
  subm ra address                  # is address >= max error
  jumpn start

  load ra address
  call uart_tx_hex                 # tx address
  call uart_tx_colon               # tx colon

  move ra 0                        # line length count
  store ra count

decode_NUM_multiple_read_loop:                  
  call uart_tx_space       

  load ra address  
  load ra (ra)                     # read data at address
  store ra tmp
  call uart_tx_hex                 # tx data

  load ra max_address              # is address > max_address
  subm ra address
  jumpz decode_NUM_multiple_read_exit

  load ra address                  # inc address
  add ra 1
  store ra address

  load ra count                    # max line length?
  add ra 1 
  store ra count
  sub ra 16
  jumpnz decode_NUM_multiple_read_loop

  call uart_tx_lf                  # yes new line
  call uart_tx_cr

  load ra address
  call uart_tx_hex                 # tx address
  call uart_tx_colon               # tx colon
       
  move ra 0                        # reset line count
  store ra count 
  jump decode_NUM_multiple_read_loop

decode_NUM_multiple_read_exit:
  move ra 0
  store ra mode
  store ra current_command   

  call uart_tx_lf              
  call uart_tx_cr
        
  jump process_BUF                 # continue

decode_NUM_single_write: 
  move ra rc			           # save generated data
  store ra data

  load ra address
  call uart_tx_hex                 # text data
  call uart_tx_colon               # tx address
  call uart_tx_space
  
  load ra address
  load ra (ra)                     # read data at address
  #call uart_tx_hex                 # text data

  call uart_tx_lf                  # yes new line
  call uart_tx_cr
 
  load ra address                  # read address
  move rb ra
  load ra data                     # read data
  store ra (rb)                    # write data
      
  jump process_BUF                 # continue

decode_NUM_multiple_write: 
  move ra rc			           # save generated data
  store ra data

  load ra address                  # read address
  add ra 1                         # inc
  store ra address
  move rb ra

  load ra data                     # read data
  store ra (rb)

  jump process_BUF                 # continue

# 20  SP     
# 2E  .    
# 3A  :    
# 52  R    
# 72  r    

decode_CMD:
  load ra tmp                      # read char
  store ra current_command

  cmp ra 0x20
  jumpz decode_CMD_space	       # space
  cmp ra 0x2E
  jumpz decode_CMD_dot		       # full stop = read
  cmp ra 0x3A
  jumpz decode_CMD_colon	       # colon = write
  cmp ra 0x52
  jumpz decode_CMD_run 	           # R = run
  cmp ra 0x72
  jumpz decode_CMD_run 	           # r = run

  jump start                       # error, restart

decode_CMD_space:
  and rd 0xFF                      # was there a number
  jumpnz decode_CMD_space_update
  jump start                       # error, restart

decode_CMD_space_update:
  load ra mode                  
  sub ra 1
  jumpn decode_NUM_single_read     # if 0 mode read
  jumpz decode_NUM_multiple_read   # if 1 mode multiple read
  sub ra 1
  jumpz decode_CMD_space_update_1  # if 2 mode write
  jump decode_NUM_multiple_write   # if 3 mode multiple write
             
decode_CMD_space_update_1:
  move ra 3                        # update mode to write multiple               
  store ra mode
  jump decode_NUM_single_write

decode_CMD_dot:
  load ra  previous_command
  sub ra 0x2E                      # was previous command a dot
  jumpnz decode_CMD_dot_update
  jump start                       # error, restart

decode_CMD_dot_update:
  and rd 0xFF                      # was there a number
  jumpz decode_CMD_dot_update_1

  move ra rc			           # save generated address
  store ra address
  move ra 1                        # flag read multiple               
  store ra mode           
  jump process_BUF                 # continue 

decode_CMD_dot_update_1:
  load ra address                  # no number, inc old address
  add ra 1
  store ra address
  move ra 1                        # flag read multiple               
  store ra mode         
  jump process_BUF                 # continue 

decode_CMD_colon:
  load ra  previous_command        # was previous command a colon
  sub ra 0x3A
  jumpnz decode_CMD_colon_update
  jump start                       # error, restart

decode_CMD_colon_update:
  and rd 0xFF                      # was there a number?
  jumpz decode_CMD_colon_update_1

  move ra rc			           # save generated address
  store ra address
  move ra 2                        # flag as write
  store ra mode          
  jump process_BUF                 # continue 

decode_CMD_colon_update_1:
  load ra address                  # no, increment address
  add ra 1
  store ra address
  move ra 2                        # flag as write
  store ra mode          
  jump process_BUF                 # continue 

decode_CMD_run:
  move ra rc			           # save generated address
  store ra address
  addm ra const_0x8000             # turn into a JUMP instruction
  store ra decode_CMD_run_go       # overwrite instruction

decode_CMD_run_go:
  jump decode_CMD_run_go           # run code

###############
# SUBROUTINES #
###############

# Test if char is a digit
# -----------------------
# 0 to 9 = 0x30 to 0x39 
# A to F = 0x41 to 0x46 

test_digit: 
  sub ra 0x30                      # Shift ASCII digits down
  jumpn test_digit_err             # < '0' -> invalid
  cmp ra 10
  jumpn test_digit_exit            # '0'..'9' -> valid (0..9)

  load ra tmp
  sub ra 0x37                      # Shift ASCII hex upper ('A' = 0x41 -> 10)
  cmp ra 10
  jumpn test_digit_err             # < 'A' -> invalid
  cmp ra 16
  jumpn test_digit_exit            # 'A'..'F' -> valid (10..15)

test_digit_err:
  move ra 0xFF                     # Not a valid hex char

test_digit_exit:
  ret

# RX buffer write
# ---------------
# Returns RA = 0 on success, 0xFFFF if full

rx_buffer_write:
  load ra rx_buffer_wr_index       # calc next wr_index
  add ra 1
  and ra 0x3F                                   
  subm ra rx_buffer_rd_index       # Does wr_index + 1 = rd_index?
  jumpz rx_buffer_write_full       # yes, buffer is full

  load ra rx_buffer_wr_index
  addm ra rx_buffer_address
  move rb ra
  load ra tmp
  store ra (rb)

  load ra rx_buffer_wr_index       # update wr_index
  add ra 1
  and ra 0x3F 
  store ra rx_buffer_wr_index
  move ra 0                        # Success
  ret

rx_buffer_write_full:
  move ra 0xFF                     # Buffer full
  ret

# RX buffer read
# --------------
# Returns RA = Data, or 0xFFFF if empty

rx_buffer_read:
  load ra rx_buffer_wr_index
  subm ra rx_buffer_rd_index       # Does wr_index = rd_index?
  jumpz rx_buffer_read_empty       # yes, buffer is empty

  load ra rx_buffer_rd_index       # read value from buffer
  addm ra rx_buffer_address
  move rb ra
  load ra (rb)
  store ra tmp

  load ra rx_buffer_rd_index       # update rd_index
  add ra 1
  and ra 0x3F
  store ra rx_buffer_rd_index

  load ra tmp                      # Return character
  ret

rx_buffer_read_empty:
  move ra 0xFF                     # Buffer empty
  ret

# TX buffer write
# ---------------
# Returns RA = 0 on success, 0xFFFF if full

tx_buffer_write:
  load ra tx_buffer_wr_index       # calc next wr_index
  add ra 1
  and ra 0x3F                                   
  subm ra tx_buffer_rd_index       # Does wr_index + 1 = rd_index?
  jumpz tx_buffer_write_full       # yes, buffer is full

  load ra tx_buffer_wr_index
  addm ra tx_buffer_address
  move rb ra
  load ra tmp
  store ra (rb)

  load ra tx_buffer_wr_index       # update wr_index
  add ra 1
  and ra 0x3F 
  store ra tx_buffer_wr_index
  move ra 0                        # Success
  ret

tx_buffer_write_full:
  move ra 0xFF                     # Buffer full
  ret

# TX buffer read
# --------------
# Returns RA = Data, or 0xFFFF if empty

tx_buffer_read:
  load ra tx_buffer_wr_index
  subm ra tx_buffer_rd_index       # Does wr_index = rd_index?
  jumpz tx_buffer_read_empty       # yes, buffer is empty

  load ra tx_buffer_rd_index       # read value from buffer
  addm ra tx_buffer_address
  move rb ra
  load ra (rb)
  store ra tmp

  load ra tx_buffer_rd_index       # update rd_index
  add ra 1
  and ra 0x3F
  store ra tx_buffer_rd_index

  load ra tmp                      # Return character
  ret

tx_buffer_read_empty:
  move ra 0xFF                     # Buffer empty
  ret

# TX BUFFER UPDATE
# ----------------

tx_buffer_update:  
  call tx_buffer_write
  cmp ra 0xFF
  jumpnz tx_buffer_update_exit

  load ra mode
  sub ra 2
  jumpp tx_buffer_update_exit

  load ra tmp
  store ra tmp1

tx_buffer_update_wait:
  call uart_tx_ready
  cmp ra 0xFF
  jumpz tx_buffer_update_wait

  call tx_buffer_read
  cmp ra 0xFF                      # is there data to TX
  jumpz tx_buffer_update_exit
  call uart_tx

  load ra tmp1
  store ra tmp
  call tx_buffer_write

tx_buffer_update_exit:
  ret

###########################
# SERIAL PORT SUBROUTINES #
###########################

# STATUS REGISTER VERSION-A
# -------------------------
# B7 : NU            128
# B6 : NU            64
# B5 : NU            32
# B4 : NU            16
# B3 : NU            8
# B2 : TX Idle       4
# B1 : RX Idle       2
# B0 : RX Valid      1

# STATUS REGISTER VERSION-B
# -------------------------
# B7: NU (0)         128
# B6: NU (0)         64
# B5: TX Idle        32
# B4: TX FIFO Full   16
# B3: TX FIFO Empty  8
# B2: RX Idle        4
# B1: RX FIFO Full   2
# B0: RX FIFO Empty  1

# RX Char
# -------
# Returns RA = Data, or 0xFF if no valid

uart_rx:
  load ra UART_STATUS              # test status  
  and ra 0x01                      # VERSION-A        
  jumpz uart_rx_empty           

  load ra UART_RX                  
  store ra tmp
  ret

uart_rx_empty:
  move ra 0xFF                     # Not Valid
  ret 

# TX Char
# -------

uart_tx: 
  load ra tmp
  store ra UART_TX                 # tx ASCII char 
  ret

uart_tx_ready: 
  load ra UART_STATUS              # test status 
  and ra 0x04                      # VERSION-A        
  jumpnz uart_tx_ready_pass

uart_tx_ready_fail:
  move ra 0xFF
  ret

uart_tx_ready_pass:
  move ra 0
  ret

# TX CR
# -----

uart_tx_cr:
  moveu ra 0x0D                    # tx CR 
  store ra tmp
  call tx_buffer_update
  ret

# TX LF
# -----

uart_tx_lf:
  moveu ra 0x0A                    # tx LF
  store ra tmp
  call tx_buffer_update

# TX SP
# -----

uart_tx_space: 
  moveu ra 0x20                    # tx SPACE
  store ra tmp
  call tx_buffer_update
  ret

# TX :
# ----

uart_tx_colon: 
  moveu ra 0x3A                    # tx COLON
  store ra tmp
  call tx_buffer_update
  ret

# TX PROMPT
# ---------

uart_tx_prompt: 
  moveu ra 0x5C                    # tx "\"
  store ra tmp
  call tx_buffer_update
  ret

# TX Hex 16bit
# ------------

uart_tx_hex:
  store ra nibble
  xchg ra
  asr ra
  asr ra 
  asr ra
  asr ra                           # tx X000
                    
  call print_nibble
                   
  load ra nibble
  xchg ra                          # tx 0X00

  call print_nibble

  load ra nibble                   # tx 00X0      
  asr ra
  asr ra 
  asr ra
  asr ra
                      
  call print_nibble   
                 
  load ra nibble                   # tx 000X
  call print_nibble 
  ret

print_nibble:
  and ra 0x0F
  add ra 0x30                      # Convert 0-9 to ASCII '0'-'9'
  cmp ra 0x3A
  jumpn print_nibble_write
  add ra 0x07                      # Convert 10-15 to ASCII 'A'-'F'

print_nibble_write:
  store ra tmp
  call tx_buffer_update
  ret

# TX String (must terminate with a \0) 
# ------------------------------------

uart_tx_string:
  load ra string_pointer
  move rc ra

uart_tx_string_loop: 
  load ra (rc)                     # load  char 
  and ra 0xFF
  jumpz uart_tx_string_exit        # exit if 0
  store ra tmp
  call tx_buffer_update

  add rc 1                         # inc address
  jump uart_tx_string_loop         # repeat

uart_tx_string_exit:
  ret

########
# DATA #
########

rx_buffer_rd_index:     
  .data 0

rx_buffer_wr_index:     
  .data 0

rx_buffer_address:      
  .data rx_buffer

rx_buffer:      
  space(64)

tx_buffer_rd_index:     
  .data 0

tx_buffer_wr_index:     
  .data 0

tx_buffer_address: 
  .data tx_buffer

tx_buffer:      
  space(64)

# ------------------
# - Welcome string -
# ------------------

welcome_address:
  .data welcome

welcome:
  .data 0x0A    # LF
  .data 0x0D    # CR
  .data 0x4D    # M
  .data 0x69    # i
  .data 0x6B    # k
  .data 0x65    # e
  .data 0x4D    # M
  .data 0x6F    # o
  .data 0x6E    # n
  .data 0x0A    # LF
  .data 0x0D    # CR
  .data 0x00    # NULL

# Constants
# ---------

const_0x8000:
  .data 0x8000

# Variables
# ---------

# 0 = normal
# 1 = prev read
# 2 = prev write
# 3 = prev write space

mode:
  .data 0

tmp:
  .data 0

tmp1:
  .data 0

count:
  .data 0		

current_command:
  .data 0
 
previous_command:
  .data 0

address:
  .data 0

max_address:
  .data 0

data:
  .data 0

nibble:
  .data 0

string_pointer:
  .data 0



