Advertisement
Memblers

NES UART receive timeout

Jun 7th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. testloop:
  2.       jsr get_char
  3.       ldx #0
  4.    @loop:
  5.       lda buf,x
  6.       jsr put_char
  7.       inx
  8.       cpx data_length
  9.       bne @loop
  10.       jmp testloop
  11.  
  12.  
  13. ;==================
  14. get_char:
  15.       sei
  16.       lda #$40
  17.       sta $4017
  18.       lda #$80
  19.       sta $4010
  20.       lda #$3f
  21.       sta $4013
  22.       lda #0
  23.       sta $4015
  24.       lda #$1F
  25.       sta $4015
  26.  
  27.       ldx #0
  28.    @loop:
  29.       lda #SERIAL_MASK
  30.       cli   ; enable DMC long timeout
  31.    @wait:
  32.       bit $4017
  33.       beq @wait
  34.  
  35.       ; 14 cycles
  36.       sei
  37.       lda #0
  38.       sta $4010   ; disable DMC timeout, then enable frame IRQ short timeout with LSR $4017
  39.       nop
  40.       nop
  41.       nop
  42.  
  43.  
  44. .repeat 3
  45.       lsr $4017
  46.       ror a
  47.       pha
  48.       pla
  49.  
  50.       lsr $4017
  51.       ror a
  52.       nop
  53.       nop
  54.       nop
  55.       nop
  56. .endrepeat
  57.       lsr $4017
  58.       ror a
  59.       pha
  60.       pla
  61.  
  62.       lsr $4017
  63.       ror a
  64.  
  65.       eor #$FF
  66.  
  67.       cmp #'Z'
  68.       beq @exit
  69.       sta buf,x
  70. ;      lda #0
  71. ;      sta $4010
  72. ;      sta $4017
  73.       inx
  74.       bne @loop
  75.  
  76.    @exit:
  77.       stx data_length
  78.       sei
  79.  
  80.       rts
  81.  
  82. ;==================
  83.  
  84. IRQ:
  85.       beep
  86.       lda #'I'
  87.       jsr put_char
  88.       lda #'R'
  89.       jsr put_char
  90.       lda #'Q'
  91.       jsr put_char
  92.       lda $4015
  93.       pla
  94.       pla
  95.       pla
  96.       jmp testloop
  97.       rti
  98.  
  99. ;==================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement