Skip to content

Commit

Permalink
This Apple DA: Detect The Cricket! Resolves #760
Browse files Browse the repository at this point in the history
This adds detection for a The Cricket! sound/speech/clock device
attached to an SSC in Slot 2, the usual home on a //c or Laser 128.

Idea and testing c/o @frankmilliron
  • Loading branch information
inexorabletash committed May 31, 2023
1 parent a95176c commit 0512b0e
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 0 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ Project Page: https://github.com/a2stuff/a2d
* Moved into MODULES/ directory, dedicated command added.
* Include IIgs banks E0/E1 in total memory count.
* Identify Rockwell R65C02.
* Identify The Cricket! sound/speech/clock device attached to SSC in Slot 2.
* Screen Dump: Do nothing unless an SSC is in Slot 1.

## 1.2
Expand Down
1 change: 1 addition & 0 deletions desk.acc/res/this.apple.res.da
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
.define res_string_card_type_uthernet2 "Uthernet II"
.define res_string_card_type_lcmeve "Le Chat Mauve Eve"
.define res_string_card_type_vidhd "VidHD"
.define res_string_device_type_cricket "The Cricket!"
.define res_string_unknown "(ukendt)"
.define res_string_empty "(tom)"
.define res_string_none "(ingen)"
Expand Down
1 change: 1 addition & 0 deletions desk.acc/res/this.apple.res.de
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
.define res_string_card_type_uthernet2 "Uthernet II"
.define res_string_card_type_lcmeve "Le Chat Mauve Eve"
.define res_string_card_type_vidhd "VidHD"
.define res_string_device_type_cricket "The Cricket!"
.define res_string_unknown "(unbekannt)"
.define res_string_empty "(leer)"
.define res_string_none "(keine)"
Expand Down
1 change: 1 addition & 0 deletions desk.acc/res/this.apple.res.en
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
.define res_string_card_type_uthernet2 "Uthernet II"
.define res_string_card_type_lcmeve "Le Chat Mauve Eve"
.define res_string_card_type_vidhd "VidHD"
.define res_string_device_type_cricket "The Cricket!"
.define res_string_unknown "(unknown)"
.define res_string_empty "(empty)"
.define res_string_none "(none)"
Expand Down
1 change: 1 addition & 0 deletions desk.acc/res/this.apple.res.es
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
.define res_string_card_type_uthernet2 "Uthernet II"
.define res_string_card_type_lcmeve "Le Chat Mauve Eve"
.define res_string_card_type_vidhd "VidHD"
.define res_string_device_type_cricket "The Cricket!"
.define res_string_unknown "(desconocido)"
.define res_string_empty "(vac\x12o)"
.define res_string_none "(nada)"
Expand Down
1 change: 1 addition & 0 deletions desk.acc/res/this.apple.res.fr
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
.define res_string_card_type_uthernet2 "Uthernet II"
.define res_string_card_type_lcmeve "Le Chat Mauve Eve"
.define res_string_card_type_vidhd "VidHD"
.define res_string_device_type_cricket "The Cricket!"
.define res_string_unknown "(inconnu)"
.define res_string_empty "(vide)"
.define res_string_none "(aucun)"
Expand Down
1 change: 1 addition & 0 deletions desk.acc/res/this.apple.res.it
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
.define res_string_card_type_uthernet2 "Uthernet II"
.define res_string_card_type_lcmeve "Le Chat Mauve Eve"
.define res_string_card_type_vidhd "VidHD"
.define res_string_device_type_cricket "The Cricket!"
.define res_string_unknown "(sconosciuto)"
.define res_string_empty "(vuoto)"
.define res_string_none "(nessuno)"
Expand Down
1 change: 1 addition & 0 deletions desk.acc/res/this.apple.res.pt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
.define res_string_card_type_uthernet2 "Uthernet II"
.define res_string_card_type_lcmeve "Le Chat Mauve Eve"
.define res_string_card_type_vidhd "VidHD"
.define res_string_device_type_cricket "The Cricket!"
.define res_string_unknown "(desconhecido)"
.define res_string_empty "(v@cuo)"
.define res_string_none "(nenhum)"
Expand Down
1 change: 1 addition & 0 deletions desk.acc/res/this.apple.res.sv
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
.define res_string_card_type_uthernet2 "Uthernet II"
.define res_string_card_type_lcmeve "Le Chat Mauve Eve"
.define res_string_card_type_vidhd "VidHD"
.define res_string_device_type_cricket "The Cricket!"
.define res_string_unknown "(ok{nt)"
.define res_string_empty "(t|mma)"
.define res_string_none "(ingen)"
Expand Down
159 changes: 159 additions & 0 deletions desk.acc/this.apple.s
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ str_z80: PASCAL_STRING res_string_card_type_z80
str_uthernet2: PASCAL_STRING res_string_card_type_uthernet2
str_lcmeve: PASCAL_STRING res_string_card_type_lcmeve
str_vidhd: PASCAL_STRING res_string_card_type_vidhd
str_cricket: PASCAL_STRING res_string_device_type_cricket
str_unknown: PASCAL_STRING res_string_unknown
str_empty: PASCAL_STRING res_string_empty
str_none: PASCAL_STRING res_string_none
Expand Down Expand Up @@ -1210,6 +1211,18 @@ draw: php
jsr ShowSmartPortDeviceNames
END_IF

;; Special case for Slot 2
lda slot
cmp #2
IF_EQ
jsr SetSlotPtr
param_call WithInterruptsDisabled, DetectTheCricket
IF_CS
param_call DrawString, str_list_separator
param_call DrawString, str_cricket
END_IF
END_IF

;; Special case for Slot 3 cards
lda slot
cmp #3
Expand Down Expand Up @@ -1680,6 +1693,152 @@ fail: clc
rts
.endproc ; DetectMockingboard

;;; ============================================================
;;; Detect The Cricket! attached to SSC in slot 2

;;; Inputs: $06 points at $Cs00
;;; Outputs: C=1 if detected, C=0 otherwise
;;; Assert: Interrupts disabled

.proc DetectTheCricket
ptr := $06

;; Look for SSC
ldx #kSigSize-1
: ldy sig_offset,x
lda (ptr),y
cmp sig_value,x
bne not_found
dex
bpl :-

;; Change ptr from $Cs00 to $C0s0
lda ptr+1
pha
and #$F0
sta ptr+1
pla ; A = %1100ssss
asl ; A = $100ssss0
asl ; A = $00ssss00
asl ; A = $0ssss000
asl ; A = $ssss0000
sta ptr

TDREG = $88 ; ACIA Transmit Register (write)
RDREG = $88 ; ACIA Receive Register (read)
STATUS = $89 ; ACIA Status/Reset Register
COMMAND = $8A ; ACIA Command Register
CONTROL = $8B ; ACIA Control Register

;; Save register states
ldy #COMMAND
lda (ptr),y
sta restore_command
ldy #CONTROL
lda (ptr),y
sta restore_control

;; Configure SSC
ldy #COMMAND
lda #%00001011 ; no parity/echo/interrupts, RTS low, DTR low
sta (ptr),y
ldy #CONTROL
lda #%10011110 ; 9600 baud, 8 data bits, 2 stop bits
sta (ptr),y

;; Send "Read Cricket ID", code 0
lda #0
jsr sendbyte

jsr readbyte
bcs not_found_with_restore ; timeout
cmp #'C'|$80
bne not_found_with_restore

jsr readbyte
bcs not_found_with_restore ; timeout
bcc digit ; always

: jsr readbyte
bcs not_found_with_restore ; timeout
cmp #CHAR_RETURN|$80
beq found
digit: cmp #'0'|$80 ; < '0' ?
bcc not_found_with_restore
cmp #'9'|$80+1 ; > '9' ?
bcc :-
FALL_THROUGH_TO not_found_with_restore

not_found_with_restore:
jsr restore
FALL_THROUGH_TO not_found
not_found:
clc
rts

found:
sec
FALL_THROUGH_TO restore

;; Restore register states; preserves C
restore:
ldy #CONTROL
restore_control := *+1
lda #SELF_MODIFIED_BYTE
sta (ptr),y
ldy #COMMAND
restore_command := *+1
lda #SELF_MODIFIED_BYTE
sta (ptr),y
rts

;; Write byte in A
.proc sendbyte
pha
ldy #STATUS
: lda (ptr),y
and #(1 << 4) ; transmit register empty? (bit 4)
beq :- ; nope, keep waiting
pla
ldy #TDREG
sta (ptr),y
rts
.endproc

;; Read byte into A, or carry set if timed out
.proc readbyte
READ_DELAY_HI = $3 * 3 ; ($300 iterations is normal * 3.6MHz)

tries := $100 * READ_DELAY_HI
counter := $08

copy16 #tries, counter

ldy #STATUS
check: lda (ptr),y ; did we get it?
and #(1 << 3) ; receive register full? (bit 3)
bne ready ; yes, we read the value

dec counter
bne check
dec counter+1
bne check

sec ; failed
rts

ready: ldy #RDREG
lda (ptr),y ; actually read the register
clc
rts
.endproc

;;; SSC Signature
sig_offset: .byte $05, $07, $0B, $0C
sig_value: .byte $38, $18, $01, $31
kSigSize = * - sig_value
.endproc ; DetectTheCricket

;;; ============================================================
;;; Update `str_memory` with memory count in kilobytes

Expand Down

0 comments on commit 0512b0e

Please sign in to comment.