Mercurial > hg > Members > kono > nitros9-code
changeset 2576:35c61c91bc29
Added 6309 code from Darren
author | boisy |
---|---|
date | Mon, 16 May 2011 00:57:24 +0000 |
parents | a9a5be5114b2 |
children | 7ebb02168028 |
files | level1/modules/dw4read.asm level1/modules/dw4write.asm |
diffstat | 2 files changed, 210 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/level1/modules/dw4read.asm Sun May 15 23:09:17 2011 +0000 +++ b/level1/modules/dw4read.asm Mon May 16 00:57:24 2011 +0000 @@ -1,3 +1,137 @@ + IFNE H6309-1 + +******************************************************* +* +* DWRead - 6309 native Turbo Edition 115k / 230k +* Receive a response from the DriveWire server. +* Times out if no data received within 1.3 (0.66) seconds. +* +* THIS VERSION REQUIRES ONE OR MORE SYNC BYTES +* WHERE THE THE FINAL SYNC BYTE IS $C0 AND ANY +* PRECEDING SYNC BYTES ARE $FF. +* +* THE DATA BYTES MUST BE TRANSMITTED IN REVERSE +* BIT ORDER (MOST-SIGNIFICANT FIRST). +* +* Serial data format: 8-N-2 (TWO STOP BITS MANDATORY) +* +* Entry: +* X = storage address for incoming data +* Y = number of bytes requested +* +* Exit: +* CC = Z set on success, cleared on timeout +* Y = checksum +* U is preserved +* All others clobbered +* +BBIN equ $FF22 ; bit banger input port + +DWRead clra ; ACCA = 0, clear Carry + pshs u,dp,a,cc ; save registers (A allocates space for status) + orcc #$50 ; mask interrupts + deca ; select hardware page.. + tfr a,dp ; ..as the direct page + ldu #BBIN ; point U at input port + tfr y,w ; W = request count + leay ,x ; Y = storage ptr + ldx #0 ; initialize timeout counter + stx <$FF92 ; disable GIME interrupts + ldd <$FF92 ; clear spurious interrupts + +* Turn off PIA interrupt sources except for the CD input pin. + lda <$FF01 ; save PIA 0 controls on the stack + ldb <$FF03 + pshs d + andd #$FCFC ; clear IRQ enables + sta <$FF01 ; set new control state for PIA 0 + stb <$FF03 + lda <$FF00 ; ensure that IRQ outputs are cleared + ldb <$FF02 + lda <$FF21 ; save PIA 1 controls on the stack + ldb <$FF23 + pshs d + andd #$FCFC ; clear FIRQ enables + inca ; set CD FIRQ enable + sta <$FF21 ; set new control state for PIA 1 + stb <$FF23 + +* Wait for Sync Byte(s) or Timeout +sync1 ldd #$0102 ; ACCA = serial in mask, ACCB = shift counter +sync2 bita ,u ; sample input + beq sync3 ; branch if low + leax -1,x ; decrement timeout counter + bne sync1 ; loop if timeout has not expired + bra rxDone ; exit due to timeout +sync3 lsrb ; have there been 2 consecutive low samples? + bcc sync2 ; keep waiting if no + ldx #0 ; initialize checksum +sync4 bita ,u ; sample input + bne rxByte ; branch if input has returned hi + rorb ; bump secondary timeout counter + bcc sync4 ; branch if not timeout + bra rxDone ; exit due to timeout + +* Byte receiver loop +rxByte lda <$FF20 ; reset FIRQ + sync ; wait for start bit + leau ,u + lda ,u ; bit 0 + lsra + rolb + lda ,u++ ; bit 1 + lsra + rolb + lda -2,u ; bit 2 + lsra + rolb + lda ,--u ; bit 3 + lsra + rolb + lda ,u++ ; bit 4 + lsra + rolb + lda ,--u ; bit 5 + lsra + rolb + lda ,u+ ; bit 6 + lsra + rolb + nop + lda ,-u ; bit 7 + lsra + rolb + abx ; update checksum + stb ,y+ ; put byte to storage + decw ; decrement counter + bne rxByte ; loop if more bytes to read + clra ; status = SUCCESS +rxDone sta 5,s ; store status on stack + +* Restore previous PIA control settings + puls d ; restore original PIA 1 controls + sta <$FF21 + stb <$FF23 + puls d ; restore original PIA 0 controls + sta <$FF01 + stb <$FF03 + lda <$FF20 ; make sure the CD FIRQ has been cleared + + IFNE NITROS9-1 +* Restoration of GIME interrupts in NitrOS9 + ldd >D.IRQER ; retrieve shadow copy of IRQ/FIRQ enable regs + std <$FF92 ; restore GIME + ldd <$FF92 ; clear spurious interrupts + ENDIF + +* Clean up and return + leay ,x ; return checksum in Y + puls cc,a,dp,u ; ACCA = status; restore IRQ masks, DP and U + tsta ; set CC.Z if status = SUCCESS + rts ; return + + ELSE + ******************************************************* * * DWRead - 6809 Turbo Edition 115k / 230k @@ -119,12 +253,12 @@ stb <$FF03 lda <$FF20 ; make sure the CD FIRQ has been cleared - IF NITROS + IFNE NITROS9-1 * Restoration of GIME interrupts in NitrOS9 ldd >D.IRQER ; retrieve shadow copy of IRQ/FIRQ enable regs std <$FF92 ; restore GIME ldd <$FF92 ; clear spurious interrupts - ENDIF + ENDIF * Checksum computation clrb ; initialize checksum LSB @@ -138,3 +272,5 @@ andcc #$FE ; clear carry (no framing error) rxExit tfr d,y ; move checksum into Y without affecting CC.Z rts ; return + + ENDC
--- a/level1/modules/dw4write.asm Sun May 15 23:09:17 2011 +0000 +++ b/level1/modules/dw4write.asm Mon May 16 00:57:24 2011 +0000 @@ -1,6 +1,76 @@ + IFNE H6309-1 + ******************************************************* * -* DW4Write - 6809 Turbo Edition 115k / 230k +* DWWrite - 6309 native Turbo Edition 115k / 230k +* Send a packet to the DriveWire server. +* Serial data format: 8-N-2 +* +* Entry: +* X = address of the data to be sent +* Y = number of bytes to send +* +* Exit: +* X = address of last byte sent + 1 +* Y = 0 +* All others preserved +* +BBOUT equ $FF20 ; bit banger output port + +DWWrite pshs u,d,cc ; preserve registers + orcc #$50 ; mask interrupts + ldu #BBOUT ; point U to output port + aim #$F7,3,u ; disable sound output + +* Wait for serial input line to become idle +wait1 lda 2,u ; sample input + ldb #$80 ; setup ACCB as a shift counter +wait2 eora 2,u ; look for changing input + lsra ; shift 'changed' bit into Carry + lda 2,u ; sample input + rorb ; rotate 'changed' bit into ACCB + bcc wait2 ; loop for 8 samples + bne wait1 ; try again if changes seen in the input + +* Byte transmitter loop + incb ; ACCB = 1 (start bit / byte incrementor) +txByte lda ,x ; get data byte + stb ,u ; send start bit + asla ; move bit 0 into position + abx ; increment data ptr + sta ,u++ ; bit 0 + rora + nop + sta ,--u ; bit 1 + lsra + sta ,u++ ; bit 2 + lsra + nop + sta ,--u ; bit 3 + lsra + nop + sta ,u++ ; bit 4 + lsra + nop + sta ,--u ; bit 5 + lsra + sta ,u++ ; bit 6 + lsra + aslb ; ACCB = 2 (stop bit) + sta ,--u ; bit 7 + leau ,u + stb ,u ; send stop bit + lsrb ; ACCB = 1 (start bit / byte incrementor) + leay -1,y ; decrement counter + bne txByte ; loop if more bytes to send + + puls cc,d,u,pc ; restore registers and return + + ELSE + +******************************************************* +* +* DWWrite - 6809 Turbo Edition 115k / 230k * Send a packet to the DriveWire server. * Serial data format: 8-N-2 * @@ -63,3 +133,4 @@ puls cc,d,u,pc ; restore registers and return + ENDC