Skip to content

Commit 9f49dc4

Browse files
committed
Remove CAS_RELOCATE duplicate cassette code
1 parent 1ae3c01 commit 9f49dc4

File tree

1 file changed

+4
-125
lines changed

1 file changed

+4
-125
lines changed

src/GLABIOS.ASM

Lines changed: 4 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -617,19 +617,14 @@ BOOT_SPEED EQU BOOT_NORMAL
617617
; If Cassette enabled, some of the following features must be disabled due to
618618
; code space limitations.
619619
;
620-
CAS_RELOCATE = 0 ; keep CAS code in contiguous block
621-
622620
IF CASSETTE EQ 1
623-
CAS_RELOCATE = 1 ; relocate cassette code
624-
625621
;----------------------------------------------------------------------------;
626622
; One of the following features may be enabled in addition to cassette support.
627623
;
628624
LIGHT_PEN = 1 ; enable light pen
629625
POST_HD_PARMS = 0 ; enable POST HD size display
630626
POST_OPT_ROM = 0 ; enable POST option ROM display
631627
RANDOM_TAGLINE = 0 ; enable random tagline
632-
633628
ENDIF
634629

635630
IF POST_HD_CHECK EQ 0
@@ -5755,7 +5750,6 @@ IO_WAIT_MS_DONE:
57555750
; Output: AX = current counter
57565751
; Time: 123 clock cycles (including CALL)
57575752
;----------------------------------------------------------------------------;
5758-
57595753
IO_WAIT_LATCH PROC
57605754
MOV AL, PIT_CW <0, 0> ; Counter 0, Latch (00b)
57615755
PUSHF ; save current IF
@@ -5786,7 +5780,7 @@ IO_DELAY_MS_FDC ENDP
57865780
IO_DELAY_MS_FDC EQU IO_DELAY_MS
57875781
ENDIF
57885782

5789-
IF CAS_RELOCATE EQ 1
5783+
IF CASSETTE EQ 1
57905784
;----------------------------------------------------------------------------;
57915785
; CAS_READ_WORD: read 16 bits, add to working CRC
57925786
;----------------------------------------------------------------------------;
@@ -5855,8 +5849,7 @@ CAS_READ_BYTE_RET:
58555849

58565850
CAS_READ_BYTE ENDP
58575851
CAS_READ_WORD ENDP
5858-
ENDIF
5859-
5852+
ENDIF ; CASSETTE EQ 1
58605853
;
58615854
; 25 BYTES HERE / 22 BYTES HERE 5150
58625855
;
@@ -7358,7 +7351,6 @@ _CAS_PREV EQU BYTE PTR[SI][CAS_PREV-CAS_CRC]
73587351
_CAS_TIME_CNT EQU WORD PTR[SI][CAS_TIME_CNT-CAS_CRC]
73597352
_BIOS_BREAK EQU BYTE PTR[SI][BIOS_BREAK-CAS_CRC]
73607353

7361-
IF CAS_RELOCATE EQ 1
73627354
;----------------------------------------------------------------------------;
73637355
; CAS_CRC_ADD: Add current bit to CRC message
73647356
;----------------------------------------------------------------------------;
@@ -7397,8 +7389,7 @@ CAS_CRC_SHIFT:
73977389
XCHG _CAS_CRC, AX ; store working CRC, restore AX
73987390
RET
73997391
CAS_CRC_ADD ENDP
7400-
ENDIF
7401-
ENDIF
7392+
ENDIF ; IF CASSETTE EQ 1
74027393

74037394
;
74047395
; 7 BYTES HERE / 6 BYTES HERE 5150
@@ -10908,7 +10899,7 @@ WORD_HEX ENDP
1090810899
DWORD_HEX ENDP
1090910900

1091010901
;
10911-
; 51 BYTES HERE
10902+
; 50 BYTES HERE
1091210903
;
1091310904
BYTES_HERE INT_12
1091410905

@@ -11556,118 +11547,6 @@ CAS_READ_CYCLE_LOOP:
1155611547
CAS_READ_CYCLE ENDP
1155711548
CAS_READ ENDP
1155811549

11559-
IF CAS_RELOCATE EQ 0
11560-
;----------------------------------------------------------------------------;
11561-
; CAS_READ_WORD: read 16 bits, add to working CRC
11562-
;----------------------------------------------------------------------------;
11563-
; Output:
11564-
; AX = word read (little endian)
11565-
; CF if error
11566-
;----------------------------------------------------------------------------;
11567-
CAS_READ_WORD PROC
11568-
CALL CAS_READ_BYTE
11569-
JC CAS_READ_BYTE_RET
11570-
11571-
;----------------------------------------------------------------------------;
11572-
; CAS_READ_BYTE: read 8 bits, add to working CRC
11573-
;----------------------------------------------------------------------------;
11574-
; Output:
11575-
; AL = byte read
11576-
; CF if error
11577-
;
11578-
; Clobbers: AH, BL, DX
11579-
;----------------------------------------------------------------------------;
11580-
CAS_READ_BYTE PROC
11581-
PUSH CX ; save CX
11582-
MOV CX, 8 ; loop 8 bits
11583-
11584-
;----------------------------------------------------------------------------;
11585-
; CAS_READ_BIT: read 1 bit (2 cycles)
11586-
;----------------------------------------------------------------------------;
11587-
CAS_READ_BIT PROC
11588-
CAS_READ_BIT_LOOP:
11589-
CALL CAS_READ_CYCLE ; DX = read low cycle length
11590-
STC ; presume failure
11591-
JZ CAS_READ_BYTE_EXIT ; exit if unable to read
11592-
PUSH DX ; save low length
11593-
CALL CAS_READ_CYCLE ; DX = read high cycle length
11594-
POP AX ; AX = low length
11595-
STC ; presume failure
11596-
JZ CAS_READ_BYTE_EXIT
11597-
ADD AX, DX ; AX = full cycle length
11598-
11599-
;----------------------------------------------------------------------------;
11600-
; Determine bit value based on full cycle duration with 33% tolerance.
11601-
;
11602-
; 1: 2t * 1193182 (Hz) / 1007 Hz = ~ 2368 ticks
11603-
; 0: 2t * 1193182 (Hz) / 2014 Hz = ~ 1184 ticks
11604-
; (Note: raw timer counter readings are doubled, so must be adjusted by 2x)
11605-
;
11606-
; BEEP_1K7 = 1184 ticks = ~1007 Hz
11607-
; BEEP_2K = 592 ticks = ~2014 Hz
11608-
;
11609-
; Use median of values to determine maximum length of a '1' bit cycle:
11610-
; 1184 + 592 -> 1776 / 2 = ~ 1344 Hz = ~ 33% tolerance
11611-
;
11612-
MOV DX, BEEP_1K7 + BEEP_2K ; DX = median cycle length
11613-
CMP DX, AX ; above or below median freq?
11614-
CALL CAS_CRC_ADD ; add bit to working CRC
11615-
CMP DX, AX ; above or below median freq?
11616-
ADC BL, BL ; add bit to result
11617-
LOOP CAS_READ_BIT_LOOP
11618-
MOV AL, BL ; AL = result
11619-
CAS_READ_BIT ENDP
11620-
CLC ; no error
11621-
CAS_READ_BYTE_EXIT:
11622-
POP CX
11623-
CAS_READ_BYTE_RET:
11624-
RET
11625-
11626-
CAS_READ_BYTE ENDP
11627-
CAS_READ_WORD ENDP
11628-
ENDIF ; CAS_RELOCATE
11629-
11630-
IF CAS_RELOCATE EQ 0
11631-
;----------------------------------------------------------------------------;
11632-
; CAS_CRC_ADD: Add current bit to CRC message
11633-
;----------------------------------------------------------------------------;
11634-
; Input:
11635-
; CF = bit to add
11636-
; SI = OFFSET CAS_CRC
11637-
;----------------------------------------------------------------------------;
11638-
; This is (effectively) CRC16-CCITT as used by IBM for SDLC/HDLC. It uses a
11639-
; 0FFFFh initial/preset value, 1021h polynomial and has an expected residue
11640-
; value of 01D0Fh.
11641-
;
11642-
; cf = ( ( crc & 0x8000 ) >> 15 ) ^ CF;
11643-
; if ( cf ) {
11644-
; crc = crc ^ 0x0810;
11645-
; }
11646-
; crc = crc << 1 | cf;
11647-
; return crc;
11648-
;
11649-
; https://stackoverflow.com/questions/62771192/crc16-ccitt-calculation
11650-
; http://bitsavers.trailing-edge.com/pdf/ibm/datacomm/GA27-3093-3_SDLC_Concepts_Jun86.pdf
11651-
;----------------------------------------------------------------------------;
11652-
CAS_CRC_PRE EQU 0FFFFh ; Cassette CRC16-CCITT preset value
11653-
CAS_CRC_RES EQU 01D0Fh ; Cassette CRC16-CCITT residue value
11654-
CAS_CRC_POLY EQU 01021h ; Cassette CRC16-CCITT polynomial
11655-
11656-
CAS_CRC_ADD PROC
11657-
XCHG AX, _CAS_CRC ; get working CRC, save AX
11658-
RCR AX, 1 ; set up for RCL
11659-
RCL AX, 1 ; OF = MSB(AX) XOR CF
11660-
CLC ; CF = OF
11661-
JNO CAS_CRC_SHIFT ; if OF: AX = AX XOR 0810h
11662-
XOR AX, CAS_CRC_POLY SHR 1 ; divide by polynomial (already shifted)
11663-
STC ; CF = OF
11664-
CAS_CRC_SHIFT:
11665-
ADC AX, AX ; add bit to working CRC value
11666-
XCHG _CAS_CRC, AX ; store working CRC, restore AX
11667-
RET
11668-
CAS_CRC_ADD ENDP
11669-
ENDIF ; CAS_RELOCATE
11670-
1167111550
INT_15_CASS ENDP
1167211551
ENDIF ; ENDIF CASSETTE EQ 1
1167311552
INT_15 ENDP

0 commit comments

Comments
 (0)