8bit-Dude Posted February 27, 2022 Share Posted February 27, 2022 (edited) 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. ? Edited February 27, 2022 by 8bit-Dude 1 2 Quote Link to comment Share on other sites More sharing options...
42bs Posted February 28, 2022 Share Posted February 28, 2022 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 1 1 Quote Link to comment Share on other sites More sharing options...
8bit-Dude Posted February 28, 2022 Author Share Posted February 28, 2022 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! Quote Link to comment Share on other sites More sharing options...
+karri Posted February 28, 2022 Share Posted February 28, 2022 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. 1 Quote Link to comment Share on other sites More sharing options...
8bit-Dude Posted March 7, 2022 Author Share Posted March 7, 2022 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 1 Quote Link to comment Share on other sites More sharing options...
42bs Posted March 7, 2022 Share Posted March 7, 2022 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 Quote Link to comment Share on other sites More sharing options...
42bs Posted March 7, 2022 Share Posted March 7, 2022 (edited) 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 March 7, 2022 by 42bs Quote Link to comment Share on other sites More sharing options...
42bs Posted March 7, 2022 Share Posted March 7, 2022 @noBreak: lda contrl ora #RxIntEnable|ResetErr sta SERCTL lda #$10 sta INTRST bra @IRQexit Is partly redundant. Quote Link to comment Share on other sites More sharing options...
42bs Posted March 7, 2022 Share Posted March 7, 2022 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 1 Quote Link to comment Share on other sites More sharing options...
+karri Posted March 7, 2022 Share Posted March 7, 2022 I added this to my own cc65 version. Quote Link to comment Share on other sites More sharing options...
42bs Posted March 7, 2022 Share Posted March 7, 2022 *arg* typo: Last line must be "bra @IRQexit1" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.