Jump to content
IGNORED

CC65 Demo Code for 8bit-Hub


8bit-Dude

Recommended Posts

In order to make it easier for people to start developping games/code using the 8bit-Hub, I have added a folder on GitHub that contains a small demo code written in CC65.

 

See GitHub Code: https://github.com/8bit-Dude/8bit-Hub/tree/master/CC65

 

See Emulation of 8bit-Hub (Firmware 0.6) in Handy 0.98: http://8bit-slicks.com/?wpdmpro=handy

 

For more info on the 8bit-Hub: http://8bit-unity.com/?page_id=551

 

Note: This code can be easily ported to assembly. You simply need to use the files hub.s (generated by CC65) and comlynx.s. Then use the same API calls as shown in main.c. ?

 

8bit-Hub.PNG

Edited by 8bit-Dude
  • Like 1
  • Thanks 2
Link to comment
Share on other sites

The interrupt code kinda hurts my sizecoder's eyes (redundancy).

Here my proposal:

IRQ:
        lda     INTSET          ; Poll all pending interrupts
        and     #SERIAL_INTERRUPT
	beq	@IRQexit1
        bit     TxDone
        bmi     @tx_irq     ; Transmit in progress

        ldx     SERDAT
        lda     SERCTL
        and     #RxParityErr|RxOverrun|RxFrameErr|RxBreak
        beq     @rx_irq
        tsb     SerialStat  ; Save error condition
        bit     #RxBreak
        beq     @noBreak
        stz     TxPtrIn     ; Break received - drop buffers
        stz     TxPtrOut
        stz     RxPtrIn
        stz     RxPtrOut
@noBreak:
        lda     contrl
        ora     #RxIntEnable|ResetErr
        sta     SERCTL
        lda     #$10
        sta     INTRST
        bra     @IRQexit
@rx_irq:
        lda     contrl
        ora     #RxIntEnable|ResetErr
        sta     SERCTL
        txa
        ldx     RxPtrIn
        sta     RxBuffer,x
        txa
        inx

@cont0:
        cpx     RxPtrOut
        beq     @1
        stx     RxPtrIn
        bra     @IRQexit

@1:
        sta     RxPtrIn
        lda     #$80
        tsb     SerialStat
@tx_irq:
        ldx     TxPtrOut    ; Has all bytes been sent?
        cpx     TxPtrIn
        beq     @allSent

        lda     TxBuffer,x  ; Send next byte
        sta     SERDAT
        inc     TxPtrOut

@exit1:
        lda     #TxIntEnable|ResetErr
        bra     @IRQexit

@allSent:
        lda     SERCTL       ; All bytes sent
        bit     #TxEmpty
        beq     @exit1
        bvs     @exit1
        stz     TxDone

        lda     #RxIntEnable|ResetErr

@IRQexit0:
        ora     contrl
        sta     SERCTL

@IRQexit:
        lda     #SERIAL_INTERRUPT
        sta     INTRST
@IRQexit1:
        clc
        rts

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

49 minutes ago, 8bit-Dude said:

Thanks for that StarGunner! I will check it the code still works with those modifications.

If so, it would be worth letting Karri know about it, as he coded the original serial code in CC65!

Please test it. I have not been using the ComLynx much myself. Currently the official cc65 is changing the Lynx colour palette and marking index 0 as transparent. In an effort to make code with text more portable.

 

I may also finally spend some time to update sp65 to work with modern GIMP pcx files.

 

Streamlining ComLynx would also be a good thing.

  • Like 1
Link to comment
Share on other sites

On 2/28/2022 at 4:39 PM, 42bs said:

The interrupt code kinda hurts my sizecoder's eyes (redundancy).

Here my proposal:

 

Your code caused a compilation error on   beq  @IRQexit1 :   Error: Range error (130 not in [-128..127])

I fixed it up as follows, which saves 16 bytes from the CC65 version and seems to work correctly:

 

IRQ:
        lda     INTSET          ; Poll all pending interrupts
        and     #SERIAL_INTERRUPT
	bne	@doIRQ
		clc
		rts
		
@doIRQ:	
        bit     TxDone
        bmi     @tx_irq     ; Transmit in progress

        ldx     SERDAT
        lda     SERCTL
        and     #RxParityErr|RxOverrun|RxFrameErr|RxBreak
        beq     @rx_irq
        tsb     SerialStat  ; Save error condition
        bit     #RxBreak
        beq     @noBreak
        stz     TxPtrIn     ; Break received - drop buffers
        stz     TxPtrOut
        stz     RxPtrIn
        stz     RxPtrOut
@noBreak:
        lda     contrl
        ora     #RxIntEnable|ResetErr
        sta     SERCTL
        lda     #$10
        sta     INTRST
        bra     @IRQexit
@rx_irq:
        lda     contrl
        ora     #RxIntEnable|ResetErr
        sta     SERCTL
        txa
        ldx     RxPtrIn
        sta     RxBuffer,x
        txa
        inx

@cont0:
        cpx     RxPtrOut
        beq     @1
        stx     RxPtrIn
        bra     @IRQexit

@1:
        sta     RxPtrIn
        lda     #$80
        tsb     SerialStat
@tx_irq:
        ldx     TxPtrOut    ; Has all bytes been sent?
        cpx     TxPtrIn
        beq     @allSent

        lda     TxBuffer,x  ; Send next byte
        sta     SERDAT
        inc     TxPtrOut

@exit1:
        lda     #TxIntEnable|ResetErr
        bra     @IRQexit

@allSent:
        lda     SERCTL       ; All bytes sent
        bit     #TxEmpty
        beq     @exit1
        bvs     @exit1
        stz     TxDone

        lda     #RxIntEnable|ResetErr

@IRQexit0:
        ora     contrl
        sta     SERCTL

@IRQexit:
        lda     #SERIAL_INTERRUPT
        sta     INTRST
        clc
        rts

 

  • Like 1
Link to comment
Share on other sites

Hmm, just tried my version and I get no error. But I used these settings:

RxPtrIn equ 10
TxPtrIn equ 11
RxPtrOut equ 12
TxPtrOut equ 13
TxDone    equ 14
SerialStat equ 15
contrl    equ 16

TxBuffer    equ $2000
RxBuffer    equ $2100

 

Link to comment
Share on other sites

Ok, I guess the problem is that undefined symbols are stored as absolute addresses.

Anyway, with a bit "sorting" my version works.

Just move the code from "@allSent"  after "@1".

 

Actually IMHO would do more sorting to have the critical paths short. But that's me ;-)

Edited by 42bs
Link to comment
Share on other sites

IRQ:
        lda     INTSET          ; Poll all pending interrupts
        and     #SERIAL_INTERRUPT
	beq	@IRQexit1
        bit     TxDone
        bmi     @tx_irq     ; Transmit in progress

        ldx     SERDAT
        lda     SERCTL
        and     #RxParityErr|RxOverrun|RxFrameErr|RxBreak
	bne	@error
@rx_irq:
        lda     contrl
        ora     #RxIntEnable|ResetErr
        sta     SERCTL
        txa
        ldx     RxPtrIn
        sta     RxBuffer,x
        txa
        inx
        cpx     RxPtrOut
        beq     @1
        stx     RxPtrIn
        bra     @IRQexit

@error:
        beq     @rx_irq
        tsb     SerialStat  ; Save error condition
        bit     #RxBreak
        beq     @noBreak
        stz     TxPtrIn     ; Break received - drop buffers
        stz     TxPtrOut
        stz     RxPtrIn
        stz     RxPtrOut
@noBreak:
        lda     #RxIntEnable|ResetErr
        bra     @IRQexit0

@allSent:
        lda     SERCTL       ; All bytes sent
        bit     #TxEmpty
        beq     @exit1
        bvs     @exit1
        stz     TxDone

        lda     #RxIntEnable|ResetErr

@IRQexit0:
        ora     contrl
        sta     SERCTL

@IRQexit:
        lda     #SERIAL_INTERRUPT
        sta     INTRST
@IRQexit1:
        clc
        rts
@1:
        sta     RxPtrIn
        lda     #$80
        tsb     SerialStat
@tx_irq:
        ldx     TxPtrOut    ; Has all bytes been sent?
        cpx     TxPtrIn
        beq     @allSent

        lda     TxBuffer,x  ; Send next byte
        sta     SERDAT
        inc     TxPtrOut

@exit1:
        lda     #TxIntEnable|ResetErr
        bra     @IRQexit

 

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...