rs232.a65

     1:  LEEBB:
     2:          lda     zBITTS
     3:          beq     LEF06
     4:          bmi     @LEF00
     5:          lsr     zRODATA
     6:          ldx     #$00
     7:          bcc     @LEEC8
     8:          dex
     9:  @LEEC8:
    10:          txa
    11:          eor     zROPRTY
    12:          sta     zROPRTY
    13:          dec     zBITTS
    14:          beq     @LEED7
    15:  @LEED1:
    16:          txa
    17:  .if CompileComputer >= C64_GENERAL
    18:          and     #$04
    19:  .else
    20:          and     #$20
    21:  .endif
    22:          sta     zNXTBIT
    23:          rts
    24:  
    25:  @LEED7:
    26:          lda     #$20
    27:          bit     lM51CDR
    28:          beq     @LEEF2
    29:          bmi     @LEEFC
    30:          bvs     @LEEF6
    31:          lda     zROPRTY
    32:          bne     @LEEE7
    33:  @LEEE6:
    34:          dex
    35:  @LEEE7:
    36:          dec     zBITTS
    37:          lda     lM51CTR
    38:          bpl     @LEED1
    39:          dec     zBITTS
    40:          bne     @LEED1
    41:  @LEEF2:
    42:          inc     zBITTS
    43:          bne     @LEEE6
    44:  @LEEF6:
    45:          lda     zROPRTY
    46:          beq     @LEEE7
    47:          bne     @LEEE6
    48:  @LEEFC:
    49:          bvs     @LEEE7
    50:          bvc     @LEEE6
    51:          ; ------------------
    52:  
    53:  @LEF00:
    54:          inc     zBITTS
    55:          ldx     #$FF
    56:          bne     @LEED1
    57:  
    58:  LEF06:
    59:          lda     lM51CDR
    60:          lsr     a
    61:          bcc     @LEF13
    62:          bit     RS232_REG_2
    63:          bpl     LF016
    64:          bvc     LEF31
    65:  @LEF13:
    66:          lda     #$00
    67:          sta     zROPRTY
    68:          sta     zNXTBIT
    69:          ldx     lBITNUM
    70:          stx     zBITTS
    71:          ldy     lRODBS
    72:          cpy     lRODBE
    73:          beq     LEF39
    74:          lda     (zROBUF),y
    75:          sta     zRODATA
    76:          inc     lRODBS
    77:          rts
    78:  
    79:  LF016:
    80:          lda     #$40
    81:          .byte   ASM_BIT3
    82:  LEF31:
    83:          lda     #$10
    84:          ora     lRSSTAT
    85:          sta     lRSSTAT
    86:  LEF39:
    87:  .if CompileComputer >= C64_GENERAL
    88:          lda     #CIA_ICR_B_TA
    89:  LEF3B:  sta     CIA2 + CIA_O_ICR
    90:          eor     lENABL
    91:          ora     #CIA_ICR_BW_SET
    92:          sta     lENABL
    93:          sta     CIA2 + CIA_O_ICR
    94:  .else
    95:          lda     #$40
    96:          sta     VIA1_IEC
    97:  .endif
    98:          rts
    99:  
   100:  ; get number of bits to transmit
   101:  ;
   102:  LEF4A:
   103:          ldx     #$09
   104:          lda     #$20
   105:          bit     lM51CTR
   106:          beq     @LEF54
   107:          dex
   108:  @LEF54:
   109:          bvc     @LEF58
   110:          dex
   111:          dex
   112:  @LEF58:
   113:          rts
   114:          ; ---------------
   115:  
   116:  LEF59:  ldx     zRINONE
   117:          bne     LEF90
   118:          dec     zBITC1
   119:          beq     LEF97
   120:          bmi     LEF70
   121:          lda     zINBIT
   122:          eor     zRIPRTY
   123:          sta     zRIPRTY
   124:          lsr     zINBIT
   125:          ror     zRIDATA
   126:  LEF6D:  rts
   127:  
   128:  LEF6E:  dec     zBITC1
   129:  LEF70:  lda     zINBIT
   130:          beq     LEFDB
   131:          lda     lM51CTR
   132:          asl     a
   133:          lda     #$01
   134:          adc     zBITC1
   135:          bne     LEF6D
   136:  LEF7E:
   137:  .if CompileComputer >= C64_GENERAL
   138:          lda     #CIA_ICR_B_FLAG | CIA_ICR_BW_SET
   139:          sta     CIA2 + CIA_O_ICR
   140:          ora     lENABL
   141:          sta     lENABL
   142:  .else
   143:          lda     #$90
   144:          sta     VIA1_IEC
   145:  .endif
   146:          sta     zRINONE
   147:  .if CompileComputer >= C64_GENERAL
   148:          lda     #$02
   149:          jmp     LEF3B
   150:  .else
   151:          lda     #$20
   152:          sta     VIA1_IEC
   153:          rts
   154:  .endif
   155:  
   156:  LEF90:  lda     zINBIT
   157:          bne     LEF7E
   158:  .if CompileComputer >= C64_03 .AND CompileComputer <> C64_4064
   159:          jmp     LE4D3
   160:  .else
   161:          sta     zRINONE
   162:          rts
   163:  .endif
   164:  
   165:  LEF97:  ldy     lRIDBE
   166:          iny
   167:          cpy     lRIDBS
   168:          beq     @LEFCA
   169:          sty     lRIDBE
   170:          dey
   171:          lda     zRIDATA
   172:          ldx     lBITNUM
   173:  @LEFA9: cpx     #$09
   174:          beq     @LEFB1
   175:          lsr     a
   176:          inx
   177:          bne     @LEFA9
   178:  @LEFB1: sta     (zRIBUF),y
   179:          lda     #$20
   180:          bit     lM51CDR
   181:          beq     LEF6E
   182:          bmi     LEF6D
   183:          lda     zINBIT
   184:          eor     zRIPRTY
   185:          beq     @LEFC5
   186:          bvs     LEF6D
   187:          .byte   ASM_BIT3
   188:  @LEFC5: bvc     LEF6D
   189:          lda     #$01
   190:          .byte   ASM_BIT3
   191:  @LEFCA: lda     #$04
   192:          .byte   ASM_BIT3
   193:  LEFCD:  lda     #$80
   194:          .byte   ASM_BIT3
   195:  LEFD0:  lda     #$02
   196:          ora     lRSSTAT
   197:          sta     lRSSTAT
   198:          jmp     LEF7E
   199:  
   200:  LEFDB:  lda     zRIDATA
   201:          bne     LEFD0
   202:          beq     LEFCD
   203:  .if CompileComputer < C64_GENERAL
   204:  Rs232ErrIllegalDeviceNumber:
   205:          jmp     KErrIllegalDeviceNumber
   206:  .endif
   207:  
   208:  RS232_CHKOUT:
   209:          sta     zDFLTO
   210:          lda     lM51CDR
   211:          lsr     a
   212:          bcc     LF012
   213:          lda     #$02
   214:          bit     RS232_REG_1
   215:          bpl     LF00D
   216:          bne     LF012
   217:  
   218:  @LEFF2:
   219:  .if CompileComputer >= C64_GENERAL
   220:          lda     lENABL
   221:          and     #CIA_ICR_B_TB
   222:  .else
   223:          lda     VIA1_IEC
   224:          and     #$30
   225:  .endif
   226:          bne     @LEFF2
   227:  @LEFF9:
   228:          bit     RS232_REG_1
   229:          bvs     @LEFF9
   230:          lda     RS232_REG_1
   231:          ora     #$02
   232:          sta     RS232_REG_1
   233:  @LF006:
   234:          bit     RS232_REG_1
   235:          bvs     LF012
   236:          bmi     @LF006
   237:  
   238:  LF00D:
   239:  .if CompileComputer >= C64_GENERAL
   240:          lda     #$40
   241:          sta     lRSSTAT
   242:  .else
   243:          jsr     LF016
   244:  .endif
   245:  LF012:  clc
   246:          rts
   247:  
   248:  
   249:  LF014:
   250:  
   251:  .if CompileComputer >= C64_GENERAL
   252:          jsr     LF028
   253:  .endif
   254:  
   255:  ; Write a character to the RS232 output buffer
   256:  ;
   257:  ; The character is returned in A. If there is
   258:  ; no character in the buffer, A will contain 0.
   259:  ;
   260:  ; For C64 and above, this function also
   261:  ; sets lRSSTAT.3 (TODO: "buffer empty"?)
   262:  ;
   263:  RS232_PUTCHAR:
   264:          ldy     lRODBE                  ; is the output buffer read pointer
   265:          iny                             ; + 1
   266:          cpy     lRODBS                  ; equal to the output buffer write pointer?
   267:          beq     LF014                   ; yes -> ring buffer is full -> wait until it is empty again
   268:  
   269:          sty     lRODBE                  ; advance the output buffer write pointer, leaving room for the character to be written
   270:  
   271:          dey                             ; the location we reserved the space for is one before, thus, decrement Y again
   272:  
   273:  .if CompileComputer >= C64_GENERAL
   274:          lda     zPTR1
   275:  .endif
   276:          sta     (zROBUF),y              ; store the output character into the output buffer
   277:  
   278:  .if CompileComputer >= C64_GENERAL
   279:  LF028:  lda     lENABL
   280:          lsr     a                       ; test CIA_ICR_B_TA
   281:          bcs     @Rts
   282:          lda     #CIA_CRA_B_FORCE_LOAD
   283:          sta     CIA2 + CIA_O_CRA
   284:  .else
   285:          bit     VIA1_IEC
   286:          bvc     @LF102
   287:          rts
   288:  @LF102:
   289:  
   290:  .endif
   291:  
   292:          lda     lBAUDOF
   293:          sta     RS232_TIMER_LO
   294:          lda     lBAUDOF + 1
   295:          sta     RS232_TIMER_HI
   296:  
   297:  .if CompileComputer >= C64_GENERAL
   298:          lda     #$81
   299:          jsr     LEF3B
   300:          jsr     LEF06
   301:          lda     #$11
   302:          sta     CIA2 + CIA_O_CRA
   303:  @Rts:   rts
   304:  .else
   305:          lda     #$C0
   306:          sta     VIA1_IEC
   307:          jmp     LEF06
   308:  .endif
   309:  
   310:  RS232_CHKIN:
   311:          sta     zDFLTN                                  ; set default output device
   312:          lda     lM51CDR
   313:          lsr     a
   314:          bcc     @LF07D
   315:          and     #$08
   316:          beq     @LF07D
   317:          lda     #$02
   318:          bit     RS232_REG_1
   319:          bpl     LF00D
   320:          beq     @ClcRts
   321:  
   322:  @LF062:
   323:  .if CompileComputer >= C64_GENERAL
   324:          lda     lENABL
   325:          lsr     a                                       ; test CIA_ICR_B_TA
   326:          bcs     @LF062
   327:  .else
   328:          bit     VIA1_IEC
   329:          bvs     @LF062
   330:  .endif
   331:  
   332:          lda     RS232_REG_1
   333:          and     #~$02
   334:          sta     RS232_REG_1
   335:  @LF070:
   336:          lda     RS232_REG_1
   337:          and     #$04
   338:          beq     @LF070
   339:  @LF077: lda     #$90
   340:  .if CompileComputer >= C64_GENERAL
   341:          clc
   342:          jmp     LEF3B
   343:  .else
   344:          sta     VIA1_IEC
   345:  @ClcRts:
   346:          clc
   347:          rts
   348:  .endif
   349:  
   350:  @LF07D:
   351:  
   352:  .if CompileComputer >= C64_GENERAL
   353:          lda     lENABL
   354:          and     #CIA_ICR_B_FLAG | CIA_ICR_B_TB
   355:  .else
   356:          lda     VIA1_IEC
   357:          and     #$30
   358:  .endif
   359:          beq     @LF077
   360:  
   361:  .if CompileComputer >= C64_GENERAL
   362:  @ClcRts:
   363:  .endif
   364:          clc
   365:          rts
   366:  
   367:  ; Read a character from the RS232 input buffer
   368:  ;
   369:  ; The character is returned in A. If there is
   370:  ; no character in the buffer, A will contain 0.
   371:  ;
   372:  ; For C64 and above, this function also
   373:  ; sets lRSSTAT.3 (TODO: "buffer empty"?)
   374:  ;
   375:  RS232_GETCHAR:
   376:  
   377:  .if CompileComputer >= C64_GENERAL
   378:          lda     lRSSTAT                         ; as we modifiy lRSSTAT, make its value available for both if() cases.
   379:  .endif
   380:  
   381:          ldy     lRIDBS                          ; get read buffer into RS232 input buffer
   382:          cpy     lRIDBE                          ; compare with write buffer
   383:          beq     @BufferEmpty                    ; they are the same -> input buffer empty -> skip reading
   384:  
   385:  .if CompileComputer >= C64_GENERAL
   386:          and     #~$08
   387:          sta     lRSSTAT                         ; clear bit: buffer is not empty (TODO?)
   388:  .endif
   389:          lda     (zRIBUF),y                      ; get character from buffer
   390:          inc     lRIDBS                          ; increment read pointer
   391:          rts
   392:          ; ---------------
   393:  
   394:  @BufferEmpty:
   395:  
   396:  .if CompileComputer >= C64_GENERAL
   397:          ora     #$08
   398:          sta     lRSSTAT                         ; set bit: buffer empty (TODO?)
   399:  .endif
   400:          lda     #$00                            ; return: no character in buffer
   401:          rts
   402:          ; ---------------
   403:  
   404:  
   405:  LF0A4:
   406:  
   407:          pha
   408:  .if CompileComputer >= C64_GENERAL
   409:          lda     lENABL
   410:  .else
   411:          lda     VIA1_IEC
   412:  .endif
   413:          beq     @PlaRts
   414:  
   415:  @Wait:
   416:  
   417:  .if CompileComputer >= C64_GENERAL
   418:          lda     lENABL
   419:          and     #CIA_ICR_B_TA | CIA_ICR_B_TB
   420:  .else
   421:          lda     VIA1_IEC
   422:          and     #VIA_IER_B_T1 | VIA_IER_B_T2
   423:  .endif
   424:          bne     @Wait
   425:  
   426:  .if CompileComputer >= C64_GENERAL
   427:          lda     #CIA_ICR_B_FLAG
   428:          sta     CIA2 + CIA_O_ICR
   429:  .else
   430:          lda     #VIA_IER_B_CB1
   431:          sta     VIA1_IEC
   432:  .endif
   433:  
   434:  .if CompileComputer >= C64_GENERAL
   435:          lda     #$00
   436:          sta     lENABL
   437:  .endif
   438:  
   439:  @PlaRts:
   440:          pla
   441:          rts
   442:  
Valid XHTML 1.0 Strict
rs232.a65.html; generated on Fri Sep 18 21:44:54 2015 by ca65html
uz@cc65.org